@ledgerhq/coin-tezos 10.2.0 → 10.2.2
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 +25 -0
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/index.js.map +1 -1
- package/lib/logic/craftRawOperations.js +26 -17
- package/lib/logic/craftRawOperations.js.map +1 -1
- package/lib/logic/estimateFees.js +4 -4
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +9 -7
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +26 -8
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/network/tzkt.js +1 -1
- package/lib/network/tzkt.js.map +1 -1
- package/lib/test/config.d.ts +2 -22
- package/lib/test/config.d.ts.map +1 -1
- package/lib/test/config.js.map +1 -1
- package/lib/utils.d.ts +0 -3
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +17 -3
- package/lib/utils.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +1 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/logic/craftRawOperations.js +26 -17
- package/lib-es/logic/craftRawOperations.js.map +1 -1
- package/lib-es/logic/estimateFees.js +4 -4
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +9 -7
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +27 -9
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/network/tzkt.js +1 -1
- package/lib-es/network/tzkt.js.map +1 -1
- package/lib-es/test/config.d.ts +2 -22
- package/lib-es/test/config.d.ts.map +1 -1
- package/lib-es/test/config.js.map +1 -1
- package/lib-es/utils.d.ts +0 -3
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +17 -3
- package/lib-es/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/api/index-mainnet.integ.test.ts +40 -50
- package/src/api/index.integ.test.ts +60 -45
- package/src/api/index.test.ts +229 -180
- package/src/api/index.ts +5 -4
- package/src/logic/broadcast.integ.test.ts +2 -7
- package/src/logic/craftRawOperations.test.ts +11 -10
- package/src/logic/craftRawOperations.ts +35 -19
- package/src/logic/craftTransaction.integ.test.ts +2 -2
- package/src/logic/craftTransaction.test.ts +63 -95
- package/src/logic/estimateFees.integ.test.ts +19 -20
- package/src/logic/estimateFees.test.ts +30 -63
- package/src/logic/estimateFees.ts +4 -4
- package/src/logic/getBalance.test.ts +6 -6
- package/src/logic/getBlock.integ.test.ts +20 -21
- package/src/logic/getBlock.test.ts +44 -51
- package/src/logic/getBlockInfo.integ.test.ts +13 -14
- package/src/logic/getBlockInfo.test.ts +8 -7
- package/src/logic/getStakes.test.ts +17 -17
- package/src/logic/listOperations.integ.test.ts +40 -37
- package/src/logic/listOperations.test.ts +34 -31
- package/src/logic/listOperations.ts +19 -19
- package/src/logic/validateIntent.test.ts +145 -20
- package/src/logic/validateIntent.ts +32 -8
- package/src/network/bakers.integ.test.ts +1 -1
- package/src/network/bakers.test.ts +7 -15
- package/src/network/tzkt.integ.test.ts +13 -14
- package/src/network/tzkt.test.ts +194 -259
- package/src/network/tzkt.ts +1 -1
- package/src/test/config.ts +3 -1
- package/src/utils.ts +18 -3
- package/.oxlintrc.json +0 -20
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { TezosCoinConfig, TezosContext } from '../config'
|
|
5
|
+
import type { CoreTransactionInfo } from './estimateFees'
|
|
6
|
+
import type { DeepPartialReturn } from '@ledgerhq/coin-module-framework/test/utils'
|
|
5
7
|
import { getRevealFee } from '@taquito/taquito'
|
|
8
|
+
import { mockConfig } from '../test/config'
|
|
6
9
|
import { normalizePublicKeyForAddress, STAKE_USE_ALL_RESERVE_MUTEZ } from '../utils'
|
|
7
10
|
import { estimateFees } from './estimateFees'
|
|
8
11
|
import { getTezosToolkit } from './tezosToolkit'
|
|
@@ -59,14 +62,17 @@ describe('estimateFees', () => {
|
|
|
59
62
|
config: async () => currentConfig,
|
|
60
63
|
logger: () => undefined,
|
|
61
64
|
}
|
|
62
|
-
const mkConfig = (
|
|
65
|
+
const mkConfig = (feesOverrides: Partial<TezosCoinConfig['fees']> = {}): TezosCoinConfig => ({
|
|
66
|
+
...mockConfig,
|
|
67
|
+
fees: { ...defaultFeesConfig, ...feesOverrides },
|
|
68
|
+
})
|
|
63
69
|
|
|
64
70
|
beforeEach(() => {
|
|
65
71
|
jest.clearAllMocks()
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
jest
|
|
73
|
+
.mocked<DeepPartialReturn<typeof getTezosToolkit>>(getTezosToolkit)
|
|
74
|
+
.mockReturnValue(mockTezosToolkit)
|
|
75
|
+
currentConfig = mkConfig(defaultFeesConfig)
|
|
70
76
|
})
|
|
71
77
|
|
|
72
78
|
describe('signer public key from account.xpub', () => {
|
|
@@ -112,9 +118,7 @@ describe('estimateFees', () => {
|
|
|
112
118
|
burnFeeMutez: 0,
|
|
113
119
|
opSize: 100,
|
|
114
120
|
})
|
|
115
|
-
currentConfig = mkConfig({
|
|
116
|
-
fees: { ...defaultFeesConfig, minFees },
|
|
117
|
-
})
|
|
121
|
+
currentConfig = mkConfig({ minFees })
|
|
118
122
|
|
|
119
123
|
const result = await estimateFees(context, {
|
|
120
124
|
account: revealedAccount,
|
|
@@ -138,9 +142,7 @@ describe('estimateFees', () => {
|
|
|
138
142
|
burnFeeMutez: 0,
|
|
139
143
|
opSize: 100,
|
|
140
144
|
})
|
|
141
|
-
currentConfig = mkConfig({
|
|
142
|
-
fees: { ...defaultFeesConfig, minFees },
|
|
143
|
-
})
|
|
145
|
+
currentConfig = mkConfig({ minFees })
|
|
144
146
|
|
|
145
147
|
const result = await estimateFees(context, {
|
|
146
148
|
account: revealedAccount,
|
|
@@ -164,13 +166,11 @@ describe('estimateFees', () => {
|
|
|
164
166
|
burnFeeMutez: 0,
|
|
165
167
|
opSize: 100,
|
|
166
168
|
})
|
|
167
|
-
currentConfig = mkConfig({
|
|
168
|
-
fees: { ...defaultFeesConfig, minFees },
|
|
169
|
-
})
|
|
169
|
+
currentConfig = mkConfig({ minFees })
|
|
170
170
|
|
|
171
171
|
const account = { ...unrevealedAccount }
|
|
172
|
-
const transaction = {
|
|
173
|
-
mode: 'delegate'
|
|
172
|
+
const transaction: CoreTransactionInfo = {
|
|
173
|
+
mode: 'delegate',
|
|
174
174
|
recipient: 'tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D',
|
|
175
175
|
amount: BigInt(0),
|
|
176
176
|
}
|
|
@@ -191,13 +191,11 @@ describe('estimateFees', () => {
|
|
|
191
191
|
burnFeeMutez: 0,
|
|
192
192
|
opSize: 100,
|
|
193
193
|
})
|
|
194
|
-
currentConfig = mkConfig({
|
|
195
|
-
fees: { ...defaultFeesConfig, minFees: 0, minEstimatedFees: 0 },
|
|
196
|
-
})
|
|
194
|
+
currentConfig = mkConfig({ minFees: 0, minEstimatedFees: 0 })
|
|
197
195
|
|
|
198
196
|
const account = { ...unrevealedAccount }
|
|
199
|
-
const transaction = {
|
|
200
|
-
mode: 'delegate'
|
|
197
|
+
const transaction: CoreTransactionInfo = {
|
|
198
|
+
mode: 'delegate',
|
|
201
199
|
recipient: 'tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D',
|
|
202
200
|
amount: BigInt(0),
|
|
203
201
|
}
|
|
@@ -511,9 +509,7 @@ describe('estimateFees', () => {
|
|
|
511
509
|
burnFeeMutez: 0,
|
|
512
510
|
opSize: 200,
|
|
513
511
|
})
|
|
514
|
-
currentConfig = mkConfig({
|
|
515
|
-
fees: { ...defaultFeesConfig, minFees },
|
|
516
|
-
})
|
|
512
|
+
currentConfig = mkConfig({ minFees })
|
|
517
513
|
|
|
518
514
|
const result = await estimateFees(context, {
|
|
519
515
|
account: revealedAccount,
|
|
@@ -586,14 +582,7 @@ describe('estimateFees', () => {
|
|
|
586
582
|
})
|
|
587
583
|
|
|
588
584
|
it('returns fallback estimation when send has no recipient', async () => {
|
|
589
|
-
currentConfig = mkConfig({
|
|
590
|
-
fees: {
|
|
591
|
-
...defaultFeesConfig,
|
|
592
|
-
minEstimatedFees: 300,
|
|
593
|
-
minGasLimit: 600,
|
|
594
|
-
minStorageLimit: 0,
|
|
595
|
-
},
|
|
596
|
-
})
|
|
585
|
+
currentConfig = mkConfig({ minEstimatedFees: 300, minGasLimit: 600, minStorageLimit: 0 })
|
|
597
586
|
|
|
598
587
|
const result = await estimateFees(context, {
|
|
599
588
|
account: revealedAccount,
|
|
@@ -612,15 +601,7 @@ describe('estimateFees', () => {
|
|
|
612
601
|
})
|
|
613
602
|
|
|
614
603
|
it('uses fallback estimation and adds reveal fee when Taquito throws Public key not found (unrevealed)', async () => {
|
|
615
|
-
|
|
616
|
-
currentConfig = mkConfig({
|
|
617
|
-
fees: {
|
|
618
|
-
...defaultFeesConfig,
|
|
619
|
-
minEstimatedFees,
|
|
620
|
-
minGasLimit: 600,
|
|
621
|
-
minStorageLimit: 0,
|
|
622
|
-
},
|
|
623
|
-
})
|
|
604
|
+
currentConfig = mkConfig({ minEstimatedFees: 400, minGasLimit: 600, minStorageLimit: 0 })
|
|
624
605
|
mockTezosToolkit.estimate.transfer.mockRejectedValue(
|
|
625
606
|
Object.assign(new Error('Fail'), { status: 404, message: 'Public key not found' })
|
|
626
607
|
)
|
|
@@ -635,8 +616,8 @@ describe('estimateFees', () => {
|
|
|
635
616
|
})
|
|
636
617
|
|
|
637
618
|
const expectedRevealFee = getRevealFee(unrevealedAccount.address)
|
|
638
|
-
expect(result.fees).toBe(
|
|
639
|
-
expect(result.estimatedFees).toBe(BigInt(
|
|
619
|
+
expect(result.fees).toBe(400n)
|
|
620
|
+
expect(result.estimatedFees).toBe(BigInt(400 + expectedRevealFee))
|
|
640
621
|
})
|
|
641
622
|
|
|
642
623
|
it('send_token (FA2) revealed applies estimation from contract transfer', async () => {
|
|
@@ -705,15 +686,7 @@ describe('estimateFees', () => {
|
|
|
705
686
|
})
|
|
706
687
|
|
|
707
688
|
it('send_token uses fallback when Taquito throws Public key not found', async () => {
|
|
708
|
-
|
|
709
|
-
currentConfig = mkConfig({
|
|
710
|
-
fees: {
|
|
711
|
-
...defaultFeesConfig,
|
|
712
|
-
minEstimatedFees,
|
|
713
|
-
minGasLimit: 600,
|
|
714
|
-
minStorageLimit: 0,
|
|
715
|
-
},
|
|
716
|
-
})
|
|
689
|
+
currentConfig = mkConfig({ minEstimatedFees: 400, minGasLimit: 600, minStorageLimit: 0 })
|
|
717
690
|
const { transfer } = setupFa2ContractMock()
|
|
718
691
|
mockTezosToolkit.contract.at.mockResolvedValue({ methods: { transfer } })
|
|
719
692
|
mockTezosToolkit.estimate.transfer.mockRejectedValue(
|
|
@@ -733,8 +706,8 @@ describe('estimateFees', () => {
|
|
|
733
706
|
})
|
|
734
707
|
|
|
735
708
|
const expectedRevealFee = getRevealFee(unrevealedAccount.address)
|
|
736
|
-
expect(result.fees).toBe(
|
|
737
|
-
expect(result.estimatedFees).toBe(BigInt(
|
|
709
|
+
expect(result.fees).toBe(400n)
|
|
710
|
+
expect(result.estimatedFees).toBe(BigInt(400 + expectedRevealFee))
|
|
738
711
|
expect(result.amount).toBe(10n)
|
|
739
712
|
})
|
|
740
713
|
|
|
@@ -799,9 +772,7 @@ describe('estimateFees', () => {
|
|
|
799
772
|
burnFeeMutez: 0,
|
|
800
773
|
opSize: 200,
|
|
801
774
|
})
|
|
802
|
-
currentConfig = mkConfig({
|
|
803
|
-
fees: { ...defaultFeesConfig, minFees },
|
|
804
|
-
})
|
|
775
|
+
currentConfig = mkConfig({ minFees })
|
|
805
776
|
|
|
806
777
|
const result = await estimateFees(context, {
|
|
807
778
|
account: { ...revealedAccount, balance: BigInt(balance) },
|
|
@@ -839,9 +810,7 @@ describe('estimateFees', () => {
|
|
|
839
810
|
burnFeeMutez,
|
|
840
811
|
opSize: 200,
|
|
841
812
|
})
|
|
842
|
-
currentConfig = mkConfig({
|
|
843
|
-
fees: { ...defaultFeesConfig, minFees },
|
|
844
|
-
})
|
|
813
|
+
currentConfig = mkConfig({ minFees })
|
|
845
814
|
|
|
846
815
|
const result = await estimateFees(context, {
|
|
847
816
|
account: { ...revealedAccount, balance },
|
|
@@ -870,9 +839,7 @@ describe('estimateFees', () => {
|
|
|
870
839
|
burnFeeMutez: 0,
|
|
871
840
|
opSize: 200,
|
|
872
841
|
})
|
|
873
|
-
currentConfig = mkConfig({
|
|
874
|
-
fees: { ...defaultFeesConfig, minFees: 0 },
|
|
875
|
-
})
|
|
842
|
+
currentConfig = mkConfig({ minFees: 0 })
|
|
876
843
|
|
|
877
844
|
const result = await estimateFees(context, {
|
|
878
845
|
account: { ...revealedAccount, balance, stakedBalance, unstakedBalance },
|
|
@@ -239,10 +239,10 @@ export async function estimateFees(
|
|
|
239
239
|
} catch (e) {
|
|
240
240
|
if (typeof e !== 'object' || !e) throw e
|
|
241
241
|
if ('id' in e) {
|
|
242
|
-
estimation.taquitoError = (e
|
|
243
|
-
log('taquito-error', 'taquito got error ' + e.id)
|
|
242
|
+
estimation.taquitoError = String(e.id)
|
|
243
|
+
log('taquito-error', 'taquito got error ' + String(e.id))
|
|
244
244
|
} else if ('status' in e) {
|
|
245
|
-
const errorMessage =
|
|
245
|
+
const errorMessage = 'message' in e ? String(e.message) : ''
|
|
246
246
|
if (
|
|
247
247
|
errorMessage.includes('Public key not found') ||
|
|
248
248
|
errorMessage.includes('wallet or contract API')
|
|
@@ -304,7 +304,7 @@ export async function estimateFees(
|
|
|
304
304
|
throw e
|
|
305
305
|
}
|
|
306
306
|
} else {
|
|
307
|
-
const msg = String(
|
|
307
|
+
const msg = 'message' in e ? String(e.message) : ''
|
|
308
308
|
if (msg.includes('No signer has been configured')) {
|
|
309
309
|
const fallback = createFallbackEstimation(config)
|
|
310
310
|
estimation.fees = fallback.fees
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { TezosContext } from '../config'
|
|
5
5
|
import type { APITokenBalance } from '../network/types'
|
|
6
|
+
import { mockConfig } from '../test/config'
|
|
6
7
|
import { getBalance } from './getBalance'
|
|
7
8
|
|
|
8
9
|
const mockedGetAccountByAddress = jest.fn()
|
|
@@ -73,11 +74,10 @@ describe('getBalance', () => {
|
|
|
73
74
|
})
|
|
74
75
|
|
|
75
76
|
const context: TezosContext = {
|
|
76
|
-
config: async () =>
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}) as unknown as TezosCoinConfig,
|
|
77
|
+
config: async () => ({
|
|
78
|
+
...mockConfig,
|
|
79
|
+
explorer: { ...mockConfig.explorer, url: 'http://tezos.explorer.com' },
|
|
80
|
+
}),
|
|
81
81
|
logger: () => undefined,
|
|
82
82
|
}
|
|
83
83
|
it('gets the balance of a Tezos account', async () => {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { TezosCoinConfig, TezosContext } from '../config'
|
|
5
|
-
import type { OtherBlockOperation } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
5
|
import { getBlock } from './getBlock'
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -14,20 +13,19 @@ import { getBlock } from './getBlock'
|
|
|
14
13
|
* (1 mutez from a tz2 to a tz1), making the assertions deterministic.
|
|
15
14
|
*/
|
|
16
15
|
|
|
17
|
-
const shadownetConfig = (): TezosCoinConfig =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}) as TezosCoinConfig
|
|
16
|
+
const shadownetConfig = (): TezosCoinConfig => ({
|
|
17
|
+
status: { type: 'active' },
|
|
18
|
+
baker: { url: 'https://tezos-bakers.api.live.ledger.com' },
|
|
19
|
+
explorer: { url: 'https://api.shadownet.tzkt.io', maxTxQuery: 100 },
|
|
20
|
+
node: { url: 'https://rpc.shadownet.teztnets.com' },
|
|
21
|
+
fees: {
|
|
22
|
+
minGasLimit: 0,
|
|
23
|
+
minRevealGasLimit: 0,
|
|
24
|
+
minStorageLimit: 0,
|
|
25
|
+
minFees: 0,
|
|
26
|
+
minEstimatedFees: 0,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
31
29
|
|
|
32
30
|
const context: TezosContext = {
|
|
33
31
|
config: async () => shadownetConfig(),
|
|
@@ -95,7 +93,6 @@ describe('getBlock', () => {
|
|
|
95
93
|
* - finalize: pending (`.todo` until the consensus-rights-delay window passes)
|
|
96
94
|
*/
|
|
97
95
|
const SHADOWNET_STAKER = 'tz1dKrT1h6d7wP8fEzMPptG6er7mLLeQjBBY'
|
|
98
|
-
const SHADOWNET_BAKER = 'tz3Q67aMz7gSMiQRcW729sXSfuMtkyAHYfqc'
|
|
99
96
|
const STAKE_BLOCK = 3106279
|
|
100
97
|
const UNSTAKE_BLOCK = 3106307
|
|
101
98
|
|
|
@@ -108,16 +105,18 @@ describe('getBlock — Shadownet Paris staking ops', () => {
|
|
|
108
105
|
async (height, expectedOpType, expectedAmount) => {
|
|
109
106
|
const block = await getBlock(context, height)
|
|
110
107
|
const stakingTx = block.transactions.find((tx) =>
|
|
111
|
-
tx.operations.some((op) =>
|
|
108
|
+
tx.operations.some((op) => 'ledgerOpType' in op && op.ledgerOpType === expectedOpType)
|
|
112
109
|
)
|
|
113
110
|
|
|
114
111
|
if (!stakingTx) throw new Error(`No ${expectedOpType} op found in block ${height}`)
|
|
115
112
|
expect(stakingTx.feesPayer).toBe(SHADOWNET_STAKER)
|
|
116
113
|
|
|
117
|
-
const stakingOp = stakingTx.operations[0]
|
|
118
|
-
expect(stakingOp
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
const stakingOp = stakingTx.operations[0]
|
|
115
|
+
expect(stakingOp).toMatchObject({
|
|
116
|
+
type: 'other',
|
|
117
|
+
ledgerOpType: expectedOpType,
|
|
118
|
+
stakedAmount: expectedAmount,
|
|
119
|
+
})
|
|
121
120
|
expect(stakingOp).not.toHaveProperty('delegate')
|
|
122
121
|
}
|
|
123
122
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { TezosContext } from '../config'
|
|
5
5
|
import type {
|
|
6
6
|
APIDelegationType,
|
|
7
7
|
APIOriginationType,
|
|
@@ -10,11 +10,11 @@ import type {
|
|
|
10
10
|
APITokenTransfer,
|
|
11
11
|
APITransactionType,
|
|
12
12
|
} from '../network/types'
|
|
13
|
-
import
|
|
13
|
+
import { mockConfig } from '../test/config'
|
|
14
14
|
import { getBlock } from './getBlock'
|
|
15
15
|
|
|
16
16
|
const context: TezosContext = {
|
|
17
|
-
config: async () =>
|
|
17
|
+
config: async () => mockConfig,
|
|
18
18
|
logger: () => undefined,
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -51,11 +51,11 @@ jest.mock('../network', () => ({
|
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
52
|
|
|
53
53
|
function makeBlock(level = 5_000_000, hash = 'BLockHash123', timestamp = '2024-01-01T00:00:00Z') {
|
|
54
|
-
return { level, hash, timestamp }
|
|
54
|
+
return { level, hash, timestamp }
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function makeTx(overrides: Partial<APITransactionType> = {}): APITransactionType {
|
|
58
|
-
|
|
58
|
+
const defaults: APITransactionType = {
|
|
59
59
|
id: 1,
|
|
60
60
|
hash: 'opHash1',
|
|
61
61
|
type: 'transaction',
|
|
@@ -71,8 +71,8 @@ function makeTx(overrides: Partial<APITransactionType> = {}): APITransactionType
|
|
|
71
71
|
storageFee: 0,
|
|
72
72
|
allocationFee: 0,
|
|
73
73
|
status: 'applied',
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
}
|
|
75
|
+
return Object.assign(defaults, overrides)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
function makeTokenTransfer(overrides: Partial<APITokenTransfer> = {}): APITokenTransfer {
|
|
@@ -96,7 +96,7 @@ function makeTokenTransfer(overrides: Partial<APITokenTransfer> = {}): APITokenT
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function makeStaking(overrides: Partial<APIStakingType> = {}): APIStakingType {
|
|
99
|
-
|
|
99
|
+
const defaults: APIStakingType = {
|
|
100
100
|
id: 300,
|
|
101
101
|
hash: 'opStaking1',
|
|
102
102
|
type: 'staking',
|
|
@@ -116,12 +116,12 @@ function makeStaking(overrides: Partial<APIStakingType> = {}): APIStakingType {
|
|
|
116
116
|
gasLimit: 3630,
|
|
117
117
|
storageLimit: 0,
|
|
118
118
|
status: 'applied',
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
}
|
|
120
|
+
return Object.assign(defaults, overrides)
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
function makeDelegation(overrides: Partial<APIDelegationType> = {}): APIDelegationType {
|
|
124
|
-
|
|
124
|
+
const defaults: APIDelegationType = {
|
|
125
125
|
id: 200,
|
|
126
126
|
hash: 'opDelegation1',
|
|
127
127
|
type: 'delegation',
|
|
@@ -137,12 +137,12 @@ function makeDelegation(overrides: Partial<APIDelegationType> = {}): APIDelegati
|
|
|
137
137
|
status: 'applied',
|
|
138
138
|
prevDelegate: null,
|
|
139
139
|
newDelegate: { address: 'tz1Baker' },
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
}
|
|
141
|
+
return Object.assign(defaults, overrides)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
function makeOrigination(overrides: Partial<APIOriginationType> = {}): APIOriginationType {
|
|
145
|
-
|
|
145
|
+
const defaults: APIOriginationType = {
|
|
146
146
|
id: 400,
|
|
147
147
|
hash: 'opOrigination1',
|
|
148
148
|
type: 'origination',
|
|
@@ -157,12 +157,12 @@ function makeOrigination(overrides: Partial<APIOriginationType> = {}): APIOrigin
|
|
|
157
157
|
status: 'applied',
|
|
158
158
|
contractBalance: 0,
|
|
159
159
|
originatedContract: { address: 'KT1NewContract' },
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
}
|
|
161
|
+
return Object.assign(defaults, overrides)
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
function makeReveal(overrides: Partial<APIRevealType> = {}): APIRevealType {
|
|
165
|
-
|
|
165
|
+
const defaults: APIRevealType = {
|
|
166
166
|
id: 500,
|
|
167
167
|
hash: 'opReveal1',
|
|
168
168
|
type: 'reveal',
|
|
@@ -177,8 +177,8 @@ function makeReveal(overrides: Partial<APIRevealType> = {}): APIRevealType {
|
|
|
177
177
|
status: 'applied',
|
|
178
178
|
gasLimit: 10600,
|
|
179
179
|
storageLimit: 0,
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
}
|
|
181
|
+
return Object.assign(defaults, overrides)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
// ---------------------------------------------------------------------------
|
|
@@ -266,7 +266,7 @@ describe('block info and guard', () => {
|
|
|
266
266
|
// Given – one tx without a hash and one valid tx
|
|
267
267
|
mockGetBlockByLevel.mockResolvedValue(makeBlock())
|
|
268
268
|
mockFetchBlockTransactions.mockResolvedValue([
|
|
269
|
-
makeTx({ hash: undefined
|
|
269
|
+
makeTx({ hash: undefined, id: 5, amount: 500_000 }),
|
|
270
270
|
makeTx({ id: 2, hash: 'validHash', amount: 1_000_000 }),
|
|
271
271
|
])
|
|
272
272
|
|
|
@@ -282,7 +282,7 @@ describe('block info and guard', () => {
|
|
|
282
282
|
// Given – tx without id cannot be registered in txIdToHash
|
|
283
283
|
mockGetBlockByLevel.mockResolvedValue(makeBlock())
|
|
284
284
|
mockFetchBlockTransactions.mockResolvedValue([
|
|
285
|
-
makeTx({ id: undefined
|
|
285
|
+
makeTx({ id: undefined, hash: 'noIdHash', amount: 2_000_000 }),
|
|
286
286
|
])
|
|
287
287
|
|
|
288
288
|
// When
|
|
@@ -496,9 +496,9 @@ describe('fee computation and fee payer', () => {
|
|
|
496
496
|
mockGetBlockByLevel.mockResolvedValue(makeBlock())
|
|
497
497
|
mockFetchBlockTransactions.mockResolvedValue([
|
|
498
498
|
makeTx({
|
|
499
|
-
bakerFee: undefined
|
|
500
|
-
storageFee: undefined
|
|
501
|
-
allocationFee: undefined
|
|
499
|
+
bakerFee: undefined,
|
|
500
|
+
storageFee: undefined,
|
|
501
|
+
allocationFee: undefined,
|
|
502
502
|
amount: 1_000_000,
|
|
503
503
|
}),
|
|
504
504
|
])
|
|
@@ -663,9 +663,7 @@ describe('FA token transfers', () => {
|
|
|
663
663
|
expect(result.transactions).toHaveLength(1)
|
|
664
664
|
const tx = result.transactions[0]
|
|
665
665
|
expect(tx.operations).toHaveLength(4)
|
|
666
|
-
const tokenOps = tx.operations.filter(
|
|
667
|
-
(op) => op.type === 'transfer' && 'asset' in op && (op as any).asset.type === 'fa2'
|
|
668
|
-
)
|
|
666
|
+
const tokenOps = tx.operations.filter((op) => op.type === 'transfer' && op.asset.type === 'fa2')
|
|
669
667
|
expect(tokenOps).toHaveLength(2)
|
|
670
668
|
})
|
|
671
669
|
|
|
@@ -830,11 +828,12 @@ describe('FA token transfers', () => {
|
|
|
830
828
|
|
|
831
829
|
// Then — tokenId "7" must be part of the reference so different FA2 tokens under
|
|
832
830
|
// the same contract are not conflated.
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
831
|
+
expect(result.transactions[0].operations[0]).toMatchObject({
|
|
832
|
+
asset: {
|
|
833
|
+
type: 'fa2',
|
|
834
|
+
assetReference: 'KT1SpecificContract:7',
|
|
835
|
+
name: 'MyFA2Token',
|
|
836
|
+
},
|
|
838
837
|
})
|
|
839
838
|
})
|
|
840
839
|
|
|
@@ -859,8 +858,7 @@ describe('FA token transfers', () => {
|
|
|
859
858
|
const result = await getBlock(context, 5_000_000)
|
|
860
859
|
|
|
861
860
|
// Then
|
|
862
|
-
|
|
863
|
-
expect(op.asset.name).toBe('NNT')
|
|
861
|
+
expect(result.transactions[0].operations[0]).toMatchObject({ asset: { name: 'NNT' } })
|
|
864
862
|
})
|
|
865
863
|
})
|
|
866
864
|
|
|
@@ -967,7 +965,7 @@ describe('delegation operations', () => {
|
|
|
967
965
|
// Given
|
|
968
966
|
mockGetBlockByLevel.mockResolvedValue(makeBlock())
|
|
969
967
|
mockFetchBlockDelegations.mockResolvedValue([
|
|
970
|
-
makeDelegation({ hash: undefined
|
|
968
|
+
makeDelegation({ hash: undefined }),
|
|
971
969
|
makeDelegation({ id: 201, hash: 'opDelegation2' }),
|
|
972
970
|
])
|
|
973
971
|
|
|
@@ -1099,9 +1097,9 @@ describe('delegation operations', () => {
|
|
|
1099
1097
|
const result = await getBlock(context, 5_000_000)
|
|
1100
1098
|
|
|
1101
1099
|
// Then
|
|
1102
|
-
const op = result.transactions[0].operations[0]
|
|
1100
|
+
const op = result.transactions[0].operations[0]
|
|
1103
1101
|
expect(op).not.toHaveProperty('delegate')
|
|
1104
|
-
expect(op
|
|
1102
|
+
expect(op).toMatchObject({ ledgerOpType: 'UNDELEGATE' })
|
|
1105
1103
|
})
|
|
1106
1104
|
})
|
|
1107
1105
|
|
|
@@ -1154,8 +1152,7 @@ describe('staking operations', () => {
|
|
|
1154
1152
|
|
|
1155
1153
|
expect(result.transactions[0].failed).toBe(true)
|
|
1156
1154
|
expect(result.transactions[0].operations).toHaveLength(1)
|
|
1157
|
-
|
|
1158
|
-
expect(op.stakedAmount).toBe(750_000_000)
|
|
1155
|
+
expect(result.transactions[0].operations[0]).toMatchObject({ stakedAmount: 750_000_000 })
|
|
1159
1156
|
})
|
|
1160
1157
|
|
|
1161
1158
|
it('skips a staking op without sender (no operations emitted)', async () => {
|
|
@@ -1171,7 +1168,7 @@ describe('staking operations', () => {
|
|
|
1171
1168
|
it('skips a staking op with no hash', async () => {
|
|
1172
1169
|
mockGetBlockByLevel.mockResolvedValue(makeBlock())
|
|
1173
1170
|
mockFetchBlockStaking.mockResolvedValue([
|
|
1174
|
-
makeStaking({ hash: undefined
|
|
1171
|
+
makeStaking({ hash: undefined }),
|
|
1175
1172
|
makeStaking({ id: 301, hash: 'opStaking2' }),
|
|
1176
1173
|
])
|
|
1177
1174
|
|
|
@@ -1205,9 +1202,9 @@ describe('staking operations', () => {
|
|
|
1205
1202
|
|
|
1206
1203
|
const result = await getBlock(context, 5_000_000)
|
|
1207
1204
|
|
|
1208
|
-
const op = result.transactions[0].operations[0]
|
|
1205
|
+
const op = result.transactions[0].operations[0]
|
|
1209
1206
|
expect(op).not.toHaveProperty('delegate')
|
|
1210
|
-
expect(op
|
|
1207
|
+
expect(op).toMatchObject({ ledgerOpType: 'STAKE' })
|
|
1211
1208
|
})
|
|
1212
1209
|
})
|
|
1213
1210
|
|
|
@@ -1251,10 +1248,8 @@ describe('origination operations', () => {
|
|
|
1251
1248
|
expect(result.transactions).toHaveLength(1)
|
|
1252
1249
|
const tx = result.transactions[0]
|
|
1253
1250
|
expect(tx.operations).toHaveLength(1)
|
|
1254
|
-
const op = tx.operations[0]
|
|
1255
|
-
expect(op
|
|
1256
|
-
expect(op.address).toBe('tz1Deployer')
|
|
1257
|
-
expect((op as Record<string, unknown>).ledgerOpType).toBe('ORIGINATION')
|
|
1251
|
+
const op = tx.operations[0]
|
|
1252
|
+
expect(op).toMatchObject({ type: 'other', address: 'tz1Deployer', ledgerOpType: 'ORIGINATION' })
|
|
1258
1253
|
expect(op).not.toHaveProperty('amount')
|
|
1259
1254
|
})
|
|
1260
1255
|
|
|
@@ -1317,9 +1312,7 @@ describe('origination operations', () => {
|
|
|
1317
1312
|
|
|
1318
1313
|
// origination tx should contain both the native transfer and the token ops
|
|
1319
1314
|
const origTx = result.transactions.find((t) => t.hash === 'opOrig1')!
|
|
1320
|
-
const tokenOps = origTx.operations.filter(
|
|
1321
|
-
(op) => op.type === 'transfer' && 'asset' in op && (op as any).asset.type === 'fa2'
|
|
1322
|
-
)
|
|
1315
|
+
const tokenOps = origTx.operations.filter((op) => op.type === 'transfer')
|
|
1323
1316
|
expect(tokenOps).toHaveLength(2) // from + to
|
|
1324
1317
|
})
|
|
1325
1318
|
|
|
@@ -1388,7 +1381,7 @@ describe('reveal operations', () => {
|
|
|
1388
1381
|
const tx = result.transactions[0]
|
|
1389
1382
|
expect(tx.fees).toBe(6535n) // 5115 + 1420
|
|
1390
1383
|
expect(tx.operations.some((op) => op.type === 'other')).toBe(true)
|
|
1391
|
-
const revealOp = tx.operations.find((op) => op.type === 'other')
|
|
1384
|
+
const revealOp = tx.operations.find((op) => op.type === 'other')
|
|
1392
1385
|
expect(revealOp).toMatchObject({ ledgerOpType: 'REVEAL' })
|
|
1393
1386
|
})
|
|
1394
1387
|
|
|
@@ -1405,7 +1398,7 @@ describe('reveal operations', () => {
|
|
|
1405
1398
|
it('skips reveals without a hash', async () => {
|
|
1406
1399
|
mockGetBlockByLevel.mockResolvedValue(makeBlock())
|
|
1407
1400
|
mockFetchBlockReveals.mockResolvedValue([
|
|
1408
|
-
makeReveal({ hash: undefined
|
|
1401
|
+
makeReveal({ hash: undefined }),
|
|
1409
1402
|
makeReveal({ id: 501, hash: 'opReveal2' }),
|
|
1410
1403
|
])
|
|
1411
1404
|
|
|
@@ -14,20 +14,19 @@ import { getBlockInfo } from './getBlockInfo'
|
|
|
14
14
|
* consistent, independently verifiable data.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
const shadownetConfig = (): TezosCoinConfig =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}) as TezosCoinConfig
|
|
17
|
+
const shadownetConfig = (): TezosCoinConfig => ({
|
|
18
|
+
status: { type: 'active' },
|
|
19
|
+
baker: { url: 'https://tezos-bakers.api.live.ledger.com' },
|
|
20
|
+
explorer: { url: 'https://api.shadownet.tzkt.io', maxTxQuery: 100 },
|
|
21
|
+
node: { url: 'https://rpc.shadownet.teztnets.com' },
|
|
22
|
+
fees: {
|
|
23
|
+
minGasLimit: 0,
|
|
24
|
+
minRevealGasLimit: 0,
|
|
25
|
+
minStorageLimit: 0,
|
|
26
|
+
minFees: 0,
|
|
27
|
+
minEstimatedFees: 0,
|
|
28
|
+
},
|
|
29
|
+
})
|
|
31
30
|
|
|
32
31
|
const context: TezosContext = {
|
|
33
32
|
config: async () => shadownetConfig(),
|