@ledgerhq/coin-evm 16.5.3 → 16.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/api/index.d.ts +5 -2
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -1
- package/lib/api/index.js.map +1 -1
- package/lib/errors.d.ts +17 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +26 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/cip64Fees.d.ts +43 -0
- package/lib/logic/cip64Fees.d.ts.map +1 -0
- package/lib/logic/cip64Fees.js +139 -0
- package/lib/logic/cip64Fees.js.map +1 -0
- package/lib/logic/feeCollectorOperations.d.ts +2 -2
- package/lib/logic/feeCollectorOperations.js +2 -2
- package/lib/logic/getBlock.d.ts +2 -2
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +99 -19
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +59 -6
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +8 -1
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js.map +1 -1
- package/lib/network/node/withNodeSources.d.ts.map +1 -1
- package/lib/network/node/withNodeSources.js +2 -0
- package/lib/network/node/withNodeSources.js.map +1 -1
- package/lib-es/api/index.d.ts +5 -2
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/errors.d.ts +17 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +21 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/cip64Fees.d.ts +43 -0
- package/lib-es/logic/cip64Fees.d.ts.map +1 -0
- package/lib-es/logic/cip64Fees.js +134 -0
- package/lib-es/logic/cip64Fees.js.map +1 -0
- package/lib-es/logic/feeCollectorOperations.d.ts +2 -2
- package/lib-es/logic/feeCollectorOperations.js +2 -2
- package/lib-es/logic/getBlock.d.ts +2 -2
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +99 -19
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +59 -6
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +8 -1
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js.map +1 -1
- package/lib-es/network/node/withNodeSources.d.ts.map +1 -1
- package/lib-es/network/node/withNodeSources.js +2 -0
- package/lib-es/network/node/withNodeSources.js.map +1 -1
- package/package.json +2 -2
- package/src/api/index.ts +4 -1
- package/src/api/tests/index.celo.integ.test.ts +93 -0
- package/src/api/tests/index.flare.integ.test.ts +2 -1
- package/src/api/tests/index.test.ts +9 -0
- package/src/errors.ts +24 -0
- package/src/logic/cip64Fees.ts +193 -0
- package/src/logic/feeCollectorOperations.ts +2 -2
- package/src/logic/getBlock.ts +170 -30
- package/src/logic/tests/cip64Fees.test.ts +277 -0
- package/src/logic/tests/getBlock.test.ts +249 -2
- package/src/network/node/rpc.common.ts +74 -7
- package/src/network/node/types.ts +8 -1
- package/src/network/node/withNodeSources.ts +3 -0
- package/src/network/tests/node/rpc.test.ts +197 -0
- package/src/network/tests/node/withNodeSources.test.ts +18 -0
|
@@ -56,6 +56,82 @@ jest.mocked(delay).mockImplementation(
|
|
|
56
56
|
() => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
|
|
57
57
|
)
|
|
58
58
|
|
|
59
|
+
// Celo block 80494727 as some nodes serve it: its deposit transaction has no `nonce`
|
|
60
|
+
const CELO_DEPOSIT_HASH = '0xe7a0b5d03b530cafc01fec8ed44cc9b6e821d5e0224dae43ecf5af01dd5bd814'
|
|
61
|
+
const celoDepositWithoutNonce = {
|
|
62
|
+
blockHash: '0x832b94266e345c9f788ba3bcf7fd52ecff13801ee9b1b1c2d036f1c06fd4597e',
|
|
63
|
+
blockNumber: '0x4cc4087',
|
|
64
|
+
from: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001',
|
|
65
|
+
gas: '0xf4240',
|
|
66
|
+
gasPrice: '0x0',
|
|
67
|
+
hash: CELO_DEPOSIT_HASH,
|
|
68
|
+
input: '0x3db6be2b',
|
|
69
|
+
mint: '0x0',
|
|
70
|
+
r: '0x0',
|
|
71
|
+
s: '0x0',
|
|
72
|
+
sourceHash: '0xf5893f7db6a4f3effe82397b9eae2a68778c65f9d0c522bba6dbdf6afbd711e5',
|
|
73
|
+
to: '0x4200000000000000000000000000000000000015',
|
|
74
|
+
transactionIndex: '0x0',
|
|
75
|
+
type: '0x7e',
|
|
76
|
+
v: '0x0',
|
|
77
|
+
value: '0x0',
|
|
78
|
+
yParity: '0x0',
|
|
79
|
+
}
|
|
80
|
+
const celoTransfer = {
|
|
81
|
+
blockHash: '0x832b94266e345c9f788ba3bcf7fd52ecff13801ee9b1b1c2d036f1c06fd4597e',
|
|
82
|
+
blockNumber: '0x4cc4087',
|
|
83
|
+
chainId: '0xa4ec',
|
|
84
|
+
from: '0x37e6d7c66d2dc9a37c326e15c9df2b5347421f93',
|
|
85
|
+
gas: '0xe049',
|
|
86
|
+
gasPrice: '0x3893edbe00',
|
|
87
|
+
hash: '0xa2099d34015c257aaca25b69ff9ec209dcb04fb83841186972dd8598fa88ec83',
|
|
88
|
+
input:
|
|
89
|
+
'0xa9059cbb0000000000000000000000004cb8c4f8b374201ae1be5b385896178c72422ec400000000000000000000000000000000000000000000000000000000000093ee',
|
|
90
|
+
nonce: '0xe269a',
|
|
91
|
+
r: '0x88a542dce02e7fed7517b3bfe2335a18f8ba6878c9c79a2fcebc8361172edb3c',
|
|
92
|
+
s: '0x644f48a3ccdf2d23ff59a8420b89c6e4cb8f321886ca076e4ee23561f39392a3',
|
|
93
|
+
to: '0x48065fbbe25f71c9282ddf5e1cd6d6a887483d5e',
|
|
94
|
+
transactionIndex: '0x1',
|
|
95
|
+
type: '0x0',
|
|
96
|
+
v: '0x149fb',
|
|
97
|
+
value: '0x0',
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function celoBlock(transactions: unknown[]): Record<string, unknown> {
|
|
101
|
+
return {
|
|
102
|
+
baseFeePerGas: '0x2ecb7ec00e',
|
|
103
|
+
difficulty: '0x0',
|
|
104
|
+
extraData: '0x0100000190000000050000002e90edd000',
|
|
105
|
+
gasLimit: '0x1c9c380',
|
|
106
|
+
gasUsed: '0x1f6b3b',
|
|
107
|
+
hash: '0x832b94266e345c9f788ba3bcf7fd52ecff13801ee9b1b1c2d036f1c06fd4597e',
|
|
108
|
+
miner: '0x4200000000000000000000000000000000000011',
|
|
109
|
+
nonce: '0x0000000000000000',
|
|
110
|
+
number: '0x4cc4087',
|
|
111
|
+
parentHash: '0x04003c8eca609659919ee03e214e378b808161e787c469d7fce3ee18ea828cbf',
|
|
112
|
+
timestamp: '0x6ad5c8dd',
|
|
113
|
+
transactions,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// The ethers implementations, before the tests mock them
|
|
118
|
+
const {
|
|
119
|
+
getBlock: ethersGetBlock,
|
|
120
|
+
getTransaction: ethersGetTransaction,
|
|
121
|
+
_perform: ethersPerform,
|
|
122
|
+
} = JsonRpcProvider.prototype
|
|
123
|
+
|
|
124
|
+
/** Serves the raw RPC responses, so that ethers formats them as it would a node's. */
|
|
125
|
+
function mockRawRpc(responses: Record<string, unknown>): jest.SpyInstance {
|
|
126
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockImplementation(ethersGetBlock)
|
|
127
|
+
jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockImplementation(ethersGetTransaction)
|
|
128
|
+
jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(ethersPerform)
|
|
129
|
+
return jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
|
|
130
|
+
if (method in responses) return responses[method]
|
|
131
|
+
throw new Error(`Method not mocked: ${method}`)
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
59
135
|
describe('EVM Family', () => {
|
|
60
136
|
let config: EvmConfigInfo
|
|
61
137
|
|
|
@@ -359,6 +435,31 @@ describe('EVM Family', () => {
|
|
|
359
435
|
})
|
|
360
436
|
})
|
|
361
437
|
|
|
438
|
+
it('should read a deposit transaction without nonce from the raw RPC', async () => {
|
|
439
|
+
mockRawRpc({
|
|
440
|
+
eth_getTransactionByHash: celoDepositWithoutNonce,
|
|
441
|
+
eth_getTransactionReceipt: {
|
|
442
|
+
transactionHash: CELO_DEPOSIT_HASH,
|
|
443
|
+
gasUsed: '0xb5e5',
|
|
444
|
+
effectiveGasPrice: '0x0',
|
|
445
|
+
status: '0x1',
|
|
446
|
+
logs: [],
|
|
447
|
+
type: '0x7e',
|
|
448
|
+
contractAddress: null,
|
|
449
|
+
},
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
const tx = await nodeApi.getTransaction(CELO_DEPOSIT_HASH)
|
|
453
|
+
|
|
454
|
+
expect(tx).toMatchObject({
|
|
455
|
+
hash: CELO_DEPOSIT_HASH,
|
|
456
|
+
blockHeight: 80494727,
|
|
457
|
+
from: '0xDeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001',
|
|
458
|
+
type: 126,
|
|
459
|
+
})
|
|
460
|
+
expect(tx).not.toHaveProperty('nonce')
|
|
461
|
+
})
|
|
462
|
+
|
|
362
463
|
it('should not fall back to the raw RPC for another ethers error', async () => {
|
|
363
464
|
jest
|
|
364
465
|
.spyOn(JsonRpcProvider.prototype, 'getTransaction')
|
|
@@ -1546,6 +1647,63 @@ describe('EVM Family', () => {
|
|
|
1546
1647
|
],
|
|
1547
1648
|
})
|
|
1548
1649
|
})
|
|
1650
|
+
|
|
1651
|
+
it.each([
|
|
1652
|
+
['no nonce', celoDepositWithoutNonce],
|
|
1653
|
+
['a null nonce', { ...celoDepositWithoutNonce, nonce: null }],
|
|
1654
|
+
])('should fallback to raw RPC block when a deposit transaction has %s', async (_, deposit) => {
|
|
1655
|
+
mockRawRpc({ eth_getBlockByNumber: celoBlock([deposit, celoTransfer]) })
|
|
1656
|
+
|
|
1657
|
+
const block = await nodeApi.getBlockByHeight(80494727, true)
|
|
1658
|
+
|
|
1659
|
+
expect(block.transactions).toEqual([
|
|
1660
|
+
{
|
|
1661
|
+
hash: CELO_DEPOSIT_HASH,
|
|
1662
|
+
value: '0',
|
|
1663
|
+
from: '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001',
|
|
1664
|
+
to: '0x4200000000000000000000000000000000000015',
|
|
1665
|
+
input: '0x3db6be2b',
|
|
1666
|
+
gasPrice: '0',
|
|
1667
|
+
gasLimit: '1000000',
|
|
1668
|
+
},
|
|
1669
|
+
expect.objectContaining({ hash: celoTransfer.hash, nonce: 927386 }),
|
|
1670
|
+
])
|
|
1671
|
+
})
|
|
1672
|
+
|
|
1673
|
+
it('should not fallback when ethers rejects another field than the nonce', async () => {
|
|
1674
|
+
const { value: _, ...withoutValue } = celoDepositWithoutNonce
|
|
1675
|
+
mockRawRpc({ eth_getBlockByNumber: celoBlock([withoutValue, celoTransfer]) })
|
|
1676
|
+
|
|
1677
|
+
// The raw parser would reject it as MalformedNodeResponse
|
|
1678
|
+
await expect(nodeApi.getBlockByHeight(80494727, true)).rejects.toMatchObject({
|
|
1679
|
+
code: 'BAD_DATA',
|
|
1680
|
+
shortMessage: expect.stringMatching(/^invalid value for value\.value /),
|
|
1681
|
+
})
|
|
1682
|
+
})
|
|
1683
|
+
|
|
1684
|
+
it('should reject a transaction without value in the raw RPC block', async () => {
|
|
1685
|
+
const { value: _, ...withoutValue } = celoTransfer
|
|
1686
|
+
mockRawRpc({ eth_getBlockByNumber: celoBlock([celoDepositWithoutNonce, withoutValue]) })
|
|
1687
|
+
|
|
1688
|
+
await expect(nodeApi.getBlockByHeight(80494727, true)).rejects.toMatchObject({
|
|
1689
|
+
name: 'MalformedNodeResponse',
|
|
1690
|
+
message: 'Malformed prefetched transaction value in eth_getBlockByNumber response',
|
|
1691
|
+
})
|
|
1692
|
+
})
|
|
1693
|
+
|
|
1694
|
+
it('should reject a malformed sender in the raw RPC block', async () => {
|
|
1695
|
+
mockRawRpc({
|
|
1696
|
+
eth_getBlockByNumber: celoBlock([
|
|
1697
|
+
celoDepositWithoutNonce,
|
|
1698
|
+
{ ...celoTransfer, from: '0xnot-an-address' },
|
|
1699
|
+
]),
|
|
1700
|
+
})
|
|
1701
|
+
|
|
1702
|
+
await expect(nodeApi.getBlockByHeight(80494727, true)).rejects.toMatchObject({
|
|
1703
|
+
name: 'MalformedNodeResponse',
|
|
1704
|
+
message: 'Malformed prefetched transaction from in eth_getBlockByNumber response',
|
|
1705
|
+
})
|
|
1706
|
+
})
|
|
1549
1707
|
})
|
|
1550
1708
|
|
|
1551
1709
|
describe('getBlockReceipts', () => {
|
|
@@ -1744,6 +1902,45 @@ describe('EVM Family', () => {
|
|
|
1744
1902
|
})
|
|
1745
1903
|
})
|
|
1746
1904
|
|
|
1905
|
+
describe('getFeeCurrencies', () => {
|
|
1906
|
+
it('reads the fee currency of each transaction from the raw block, an omitted one as native', async () => {
|
|
1907
|
+
const send = mockRawRpc({
|
|
1908
|
+
eth_getBlockByNumber: {
|
|
1909
|
+
transactions: [
|
|
1910
|
+
{
|
|
1911
|
+
hash: '0xAA',
|
|
1912
|
+
type: '0x7b',
|
|
1913
|
+
feeCurrency: '0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72',
|
|
1914
|
+
},
|
|
1915
|
+
{ hash: '0xbb', type: '0x7b', feeCurrency: null },
|
|
1916
|
+
{ hash: '0xcc', type: '0x7b' },
|
|
1917
|
+
],
|
|
1918
|
+
},
|
|
1919
|
+
})
|
|
1920
|
+
|
|
1921
|
+
expect(await nodeApi.getFeeCurrencies!(80494727)).toEqual(
|
|
1922
|
+
new Map([
|
|
1923
|
+
['0xaa', '0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72'],
|
|
1924
|
+
['0xbb', null],
|
|
1925
|
+
['0xcc', null],
|
|
1926
|
+
])
|
|
1927
|
+
)
|
|
1928
|
+
expect(send).toHaveBeenCalledWith('eth_getBlockByNumber', ['0x4cc4087', true])
|
|
1929
|
+
})
|
|
1930
|
+
|
|
1931
|
+
it.each([
|
|
1932
|
+
['a block without transactions', undefined],
|
|
1933
|
+
['a transaction without hash', [{ feeCurrency: null }]],
|
|
1934
|
+
['a malformed fee currency', [{ hash: '0xaa', feeCurrency: 1 }]],
|
|
1935
|
+
])('rejects %s', async (_, transactions) => {
|
|
1936
|
+
mockRawRpc({ eth_getBlockByNumber: { transactions } })
|
|
1937
|
+
|
|
1938
|
+
await expect(nodeApi.getFeeCurrencies!(1)).rejects.toMatchObject({
|
|
1939
|
+
name: 'MalformedNodeResponse',
|
|
1940
|
+
})
|
|
1941
|
+
})
|
|
1942
|
+
})
|
|
1943
|
+
|
|
1747
1944
|
describe('traceBlockErigon', () => {
|
|
1748
1945
|
it('should return trace array when trace_block is supported', async () => {
|
|
1749
1946
|
const traceItem = {
|
|
@@ -53,6 +53,24 @@ describe('withNodeSources', () => {
|
|
|
53
53
|
expect(withNodeSources(api, config, testLogger)).not.toBe(api)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
+
it('reads fee currencies from the node, which the explorer proxy cannot', async () => {
|
|
57
|
+
const config = createMockEvmConfigInfo({
|
|
58
|
+
chainId: 1,
|
|
59
|
+
node,
|
|
60
|
+
explorer: mkEtherscanExplorer(),
|
|
61
|
+
nodeSources: nodeSourcesFromList(['explorer-proxy', 'node']),
|
|
62
|
+
})
|
|
63
|
+
const feeCurrencies = new Map([['0xabc', null]])
|
|
64
|
+
const withFeeCurrencies = mockNodeApi({
|
|
65
|
+
getFeeCurrencies: jest.fn().mockResolvedValueOnce(feeCurrencies),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const wrapped = withNodeSources(withFeeCurrencies, config, testLogger)
|
|
69
|
+
|
|
70
|
+
await expect(wrapped.getFeeCurrencies?.(100)).resolves.toBe(feeCurrencies)
|
|
71
|
+
expect(withNodeSources(api, config, testLogger).getFeeCurrencies).toBeUndefined()
|
|
72
|
+
})
|
|
73
|
+
|
|
56
74
|
describe('getBlockByHeight', () => {
|
|
57
75
|
it('forwards successful calls unchanged', async () => {
|
|
58
76
|
const config = createMockEvmConfigInfo({
|