@rosen-bridge/abstract-extractor 2.0.3 → 2.1.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 +11 -0
- package/dist/abstractExtractor.js +1 -1
- package/dist/ergo/AbstractErgoExtractor.js +2 -3
- package/dist/ergo/AbstractErgoExtractorAction.d.ts +1 -1
- package/dist/ergo/AbstractErgoExtractorAction.d.ts.map +1 -1
- package/dist/ergo/AbstractErgoExtractorAction.js +4 -6
- package/dist/ergo/AbstractErgoExtractorEntity.d.ts.map +1 -1
- package/dist/ergo/AbstractErgoExtractorEntity.js +2 -2
- package/dist/ergo/initializable/AbstractInitializable.js +1 -1
- package/dist/ergo/initializable/AbstractInitializableAction.d.ts +1 -1
- package/dist/ergo/initializable/AbstractInitializableAction.d.ts.map +1 -1
- package/dist/ergo/initializable/AbstractInitializableAction.js +1 -1
- package/dist/ergo/network/AbstractNetwork.js +1 -1
- package/dist/ergo/network/ExplorerNetwork.js +1 -1
- package/dist/ergo/network/NodeNetwork.js +1 -1
- package/dist/lib/abstractExtractor.d.ts +25 -0
- package/dist/lib/abstractExtractor.d.ts.map +1 -0
- package/dist/lib/abstractExtractor.js +3 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +4 -0
- package/dist/lib/ergo/AbstractErgoExtractor.d.ts +80 -0
- package/dist/lib/ergo/AbstractErgoExtractor.d.ts.map +1 -0
- package/dist/lib/ergo/AbstractErgoExtractor.js +142 -0
- package/dist/lib/ergo/AbstractErgoExtractorAction.d.ts +92 -0
- package/dist/lib/ergo/AbstractErgoExtractorAction.d.ts.map +1 -0
- package/dist/lib/ergo/AbstractErgoExtractorAction.js +222 -0
- package/dist/lib/ergo/AbstractErgoExtractorEntity.d.ts +11 -0
- package/dist/lib/ergo/AbstractErgoExtractorEntity.d.ts.map +1 -0
- package/dist/lib/ergo/AbstractErgoExtractorEntity.js +57 -0
- package/dist/lib/ergo/index.d.ts +10 -0
- package/dist/lib/ergo/index.d.ts.map +1 -0
- package/dist/lib/ergo/index.js +10 -0
- package/dist/lib/ergo/initializable/AbstractInitializable.d.ts +48 -0
- package/dist/lib/ergo/initializable/AbstractInitializable.d.ts.map +1 -0
- package/dist/lib/ergo/initializable/AbstractInitializable.js +163 -0
- package/dist/lib/ergo/initializable/AbstractInitializableAction.d.ts +14 -0
- package/dist/lib/ergo/initializable/AbstractInitializableAction.d.ts.map +1 -0
- package/dist/lib/ergo/initializable/AbstractInitializableAction.js +16 -0
- package/dist/lib/ergo/initializable/index.d.ts +3 -0
- package/dist/lib/ergo/initializable/index.d.ts.map +1 -0
- package/dist/lib/ergo/initializable/index.js +3 -0
- package/dist/lib/ergo/interfaces.d.ts +47 -0
- package/dist/lib/ergo/interfaces.d.ts.map +1 -0
- package/dist/lib/ergo/interfaces.js +8 -0
- package/dist/lib/ergo/network/AbstractNetwork.d.ts +26 -0
- package/dist/lib/ergo/network/AbstractNetwork.d.ts.map +1 -0
- package/dist/lib/ergo/network/AbstractNetwork.js +3 -0
- package/dist/lib/ergo/network/ExplorerNetwork.d.ts +74 -0
- package/dist/lib/ergo/network/ExplorerNetwork.d.ts.map +1 -0
- package/dist/lib/ergo/network/ExplorerNetwork.js +185 -0
- package/dist/lib/ergo/network/NodeNetwork.d.ts +60 -0
- package/dist/lib/ergo/network/NodeNetwork.d.ts.map +1 -0
- package/dist/lib/ergo/network/NodeNetwork.js +131 -0
- package/dist/lib/ergo/utils.d.ts +8 -0
- package/dist/lib/ergo/utils.d.ts.map +1 -0
- package/dist/lib/ergo/utils.js +16 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +4 -0
- package/dist/tests/AbstractErgoExtractor.mock.d.ts +11 -0
- package/dist/tests/AbstractErgoExtractor.mock.d.ts.map +1 -0
- package/dist/tests/AbstractErgoExtractor.mock.js +11 -0
- package/dist/tests/AbstractErgoExtractor.spec.d.ts +2 -0
- package/dist/tests/AbstractErgoExtractor.spec.d.ts.map +1 -0
- package/dist/tests/AbstractErgoExtractor.spec.js +240 -0
- package/dist/tests/AbstractErgoExtractorAction.mock.d.ts +15 -0
- package/dist/tests/AbstractErgoExtractorAction.mock.d.ts.map +1 -0
- package/dist/tests/AbstractErgoExtractorAction.mock.js +27 -0
- package/dist/tests/AbstractErgoExtractorAction.spec.d.ts +2 -0
- package/dist/tests/AbstractErgoExtractorAction.spec.d.ts.map +1 -0
- package/dist/tests/AbstractErgoExtractorAction.spec.js +221 -0
- package/dist/tests/initializable/AbstractInitializable.mock.d.ts +61 -0
- package/dist/tests/initializable/AbstractInitializable.mock.d.ts.map +1 -0
- package/dist/tests/initializable/AbstractInitializable.mock.js +18 -0
- package/dist/tests/initializable/AbstractInitializable.spec.d.ts +2 -0
- package/dist/tests/initializable/AbstractInitializable.spec.d.ts.map +1 -0
- package/dist/tests/initializable/AbstractInitializable.spec.js +299 -0
- package/dist/tests/initializable/AbstractInitializableAction.mock.d.ts +15 -0
- package/dist/tests/initializable/AbstractInitializableAction.mock.d.ts.map +1 -0
- package/dist/tests/initializable/AbstractInitializableAction.mock.js +27 -0
- package/dist/tests/initializable/AbstractInitializableAction.spec.d.ts +2 -0
- package/dist/tests/initializable/AbstractInitializableAction.spec.d.ts.map +1 -0
- package/dist/tests/initializable/AbstractInitializableAction.spec.js +54 -0
- package/dist/tests/initializable/testData.d.ts +94 -0
- package/dist/tests/initializable/testData.d.ts.map +1 -0
- package/dist/tests/initializable/testData.js +235 -0
- package/dist/tests/network/ExplorerNetwork.spec.d.ts +2 -0
- package/dist/tests/network/ExplorerNetwork.spec.d.ts.map +1 -0
- package/dist/tests/network/ExplorerNetwork.spec.js +61 -0
- package/dist/tests/network/NodeNetwork.spec.d.ts +2 -0
- package/dist/tests/network/NodeNetwork.spec.d.ts.map +1 -0
- package/dist/tests/network/NodeNetwork.spec.js +48 -0
- package/dist/tests/network/testData.d.ts +752 -0
- package/dist/tests/network/testData.d.ts.map +1 -0
- package/dist/tests/network/testData.js +1401 -0
- package/dist/tests/testData.d.ts +32 -0
- package/dist/tests/testData.d.ts.map +1 -0
- package/dist/tests/testData.js +121 -0
- package/dist/tests/testUtils.d.ts +9 -0
- package/dist/tests/testUtils.d.ts.map +1 -0
- package/dist/tests/testUtils.js +31 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +18 -0
- package/lib/abstractExtractor.ts +1 -1
- package/lib/ergo/AbstractErgoExtractor.ts +12 -12
- package/lib/ergo/AbstractErgoExtractorAction.ts +26 -31
- package/lib/ergo/AbstractErgoExtractorEntity.ts +5 -1
- package/lib/ergo/initializable/AbstractInitializable.ts +19 -19
- package/lib/ergo/initializable/AbstractInitializableAction.ts +7 -3
- package/lib/ergo/network/AbstractNetwork.ts +2 -2
- package/lib/ergo/network/ExplorerNetwork.ts +11 -11
- package/lib/ergo/network/NodeNetwork.ts +9 -9
- package/package.json +11 -16
- package/tests/AbstractErgoExtractor.mock.ts +2 -2
- package/tests/AbstractErgoExtractor.spec.ts +6 -7
- package/tests/AbstractErgoExtractorAction.mock.ts +3 -3
- package/tests/AbstractErgoExtractorAction.spec.ts +8 -9
- package/tests/initializable/AbstractInitializable.mock.ts +4 -4
- package/tests/initializable/AbstractInitializable.spec.ts +15 -16
- package/tests/initializable/AbstractInitializableAction.mock.ts +3 -3
- package/tests/initializable/AbstractInitializableAction.spec.ts +2 -3
- package/tests/network/ExplorerNetwork.spec.ts +2 -4
- package/tests/network/NodeNetwork.spec.ts +0 -1
- package/tests/testUtils.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +2 -1
- package/vitest.config.ts +1 -0
|
@@ -48,7 +48,7 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
48
48
|
* @param tx
|
|
49
49
|
*/
|
|
50
50
|
private convertTransaction = (
|
|
51
|
-
tx: IndexedErgoTransaction
|
|
51
|
+
tx: IndexedErgoTransaction,
|
|
52
52
|
): ExtendedTransaction => {
|
|
53
53
|
return {
|
|
54
54
|
id: tx.id || '',
|
|
@@ -77,13 +77,13 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
77
77
|
*/
|
|
78
78
|
getSpendingInfo = async (
|
|
79
79
|
boxId: string,
|
|
80
|
-
spendTxId: string
|
|
80
|
+
spendTxId: string,
|
|
81
81
|
): Promise<BlockInfo & { spendIndex: number }> => {
|
|
82
82
|
const tx = await this.api.getTxById(spendTxId);
|
|
83
83
|
const spendIndex = tx.inputs?.findIndex((box) => box.boxId == boxId);
|
|
84
84
|
if (spendIndex == undefined)
|
|
85
85
|
throw Error(
|
|
86
|
-
`Impossible behavior, the box [${boxId}] should have been spent in tx [${spendTxId}]
|
|
86
|
+
`Impossible behavior, the box [${boxId}] should have been spent in tx [${spendTxId}]`,
|
|
87
87
|
);
|
|
88
88
|
return {
|
|
89
89
|
hash: tx.blockId,
|
|
@@ -102,7 +102,7 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
102
102
|
getBoxesByAddress = async (
|
|
103
103
|
address: string,
|
|
104
104
|
offset: number,
|
|
105
|
-
limit: number
|
|
105
|
+
limit: number,
|
|
106
106
|
): Promise<{ boxes: ErgoBox[]; hasNextBatch: boolean }> => {
|
|
107
107
|
const boxes = await this.api.getBoxesByAddressUnspent(address, {
|
|
108
108
|
offset: offset,
|
|
@@ -112,7 +112,7 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
112
112
|
if (!boxes)
|
|
113
113
|
throw new Error('Ergo node BoxesByAddress api expected to have items');
|
|
114
114
|
const ergoBoxes = await Promise.all(
|
|
115
|
-
boxes.map(async (box) => await this.convertBox(box))
|
|
115
|
+
boxes.map(async (box) => await this.convertBox(box)),
|
|
116
116
|
);
|
|
117
117
|
return { boxes: ergoBoxes, hasNextBatch: boxes.length > 0 };
|
|
118
118
|
};
|
|
@@ -127,7 +127,7 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
127
127
|
getBoxesByTokenId = async (
|
|
128
128
|
tokenId: string,
|
|
129
129
|
offset: number,
|
|
130
|
-
limit: number
|
|
130
|
+
limit: number,
|
|
131
131
|
): Promise<{ boxes: ErgoBox[]; hasNextBatch: boolean }> => {
|
|
132
132
|
const boxes = await this.api.getBoxesByTokenId(tokenId, {
|
|
133
133
|
offset: offset,
|
|
@@ -136,7 +136,7 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
136
136
|
if (!boxes.items)
|
|
137
137
|
throw new Error('Ergo node BoxesByTokenId api expected to have items');
|
|
138
138
|
const ergoBoxes = await Promise.all(
|
|
139
|
-
boxes.items.map(async (box) => await this.convertBox(box))
|
|
139
|
+
boxes.items.map(async (box) => await this.convertBox(box)),
|
|
140
140
|
);
|
|
141
141
|
return { boxes: ergoBoxes, hasNextBatch: boxes.items.length > 0 };
|
|
142
142
|
};
|
|
@@ -151,7 +151,7 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
151
151
|
getAddressTransactionsWithOffsetLimit = async (
|
|
152
152
|
address: string,
|
|
153
153
|
offset: number,
|
|
154
|
-
limit: number
|
|
154
|
+
limit: number,
|
|
155
155
|
): Promise<{ items: Array<ExtendedTransaction>; total: number }> => {
|
|
156
156
|
const txs = await this.api.getTxsByAddress(address, {
|
|
157
157
|
offset,
|
|
@@ -159,7 +159,7 @@ export class NodeNetwork extends AbstractNetwork {
|
|
|
159
159
|
});
|
|
160
160
|
if (!txs.items)
|
|
161
161
|
throw new Error(
|
|
162
|
-
'Explorer AddressTransactions api expected to have items'
|
|
162
|
+
'Explorer AddressTransactions api expected to have items',
|
|
163
163
|
);
|
|
164
164
|
return {
|
|
165
165
|
items: txs.items.map((tx) => this.convertTransaction(tx)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosen-bridge/abstract-extractor",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Rosen Bridge extractor interfaces to work with scanner",
|
|
5
5
|
"repository": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,35 +14,30 @@
|
|
|
14
14
|
"lint": "eslint --fix . && npm run prettify",
|
|
15
15
|
"prettify": "prettier --write . --ignore-path ./.gitignore",
|
|
16
16
|
"release": "npm run test -- --run && npm run build && npm publish --access public",
|
|
17
|
-
"test": "NODE_OPTIONS
|
|
17
|
+
"test": "NODE_OPTIONS='--import tsx' vitest",
|
|
18
18
|
"type-check": "tsc --noEmit"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/lodash-es": "^4.17.12",
|
|
22
|
-
"@types/node": "^
|
|
22
|
+
"@types/node": "^22.18.0",
|
|
23
23
|
"@types/uuid": "^10.0.0",
|
|
24
|
-
"@
|
|
25
|
-
"@typescript-eslint/parser": "^6.19.1",
|
|
26
|
-
"@vitest/coverage-istanbul": "^1.2.2",
|
|
24
|
+
"@vitest/coverage-istanbul": "^3.1.4",
|
|
27
25
|
"await-semaphore": "^0.1.3",
|
|
28
|
-
"
|
|
29
|
-
"eslint-config-prettier": "^9.1.0",
|
|
30
|
-
"extensionless": "^1.9.6",
|
|
31
|
-
"prettier": "^3.2.4",
|
|
26
|
+
"tsx": "^4.19.4",
|
|
32
27
|
"typescript": "^5.3.3",
|
|
33
|
-
"vitest": "^1.
|
|
34
|
-
},
|
|
35
|
-
"engines": {
|
|
36
|
-
"node": ">=20.11.0"
|
|
28
|
+
"vitest": "^3.1.4"
|
|
37
29
|
},
|
|
38
30
|
"dependencies": {
|
|
39
31
|
"@rosen-bridge/abstract-logger": "^2.0.1",
|
|
32
|
+
"@rosen-bridge/extended-typeorm": "^0.2.1",
|
|
40
33
|
"@rosen-bridge/json-bigint": "^0.1.0",
|
|
41
|
-
"@rosen-bridge/scanner-interfaces": "^0.
|
|
34
|
+
"@rosen-bridge/scanner-interfaces": "^0.2.0",
|
|
42
35
|
"@rosen-clients/ergo-explorer": "^1.1.5",
|
|
43
36
|
"@rosen-clients/ergo-node": "^1.2.3",
|
|
44
37
|
"lodash-es": "^4.17.21",
|
|
45
|
-
"typeorm": "^0.3.20",
|
|
46
38
|
"uuid": "^9.0.0"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22.18.0"
|
|
47
42
|
}
|
|
48
43
|
}
|
|
@@ -22,11 +22,11 @@ export class MockedErgoExtractor extends AbstractErgoExtractor<
|
|
|
22
22
|
initializeBoxes: (initialBlock: BlockInfo) => Promise<void>;
|
|
23
23
|
|
|
24
24
|
hasData = (
|
|
25
|
-
box: V1.OutputInfo | OutputBox // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
25
|
+
box: V1.OutputInfo | OutputBox, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
26
26
|
) => false;
|
|
27
27
|
|
|
28
28
|
extractBoxData = (
|
|
29
|
-
box: V1.OutputInfo | OutputBox // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
|
+
box: V1.OutputInfo | OutputBox, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
30
30
|
): AbstractBoxData | undefined => {
|
|
31
31
|
return undefined;
|
|
32
32
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { V1 } from '@rosen-clients/ergo-explorer';
|
|
2
|
-
import { describe, it, expect, vitest } from 'vitest';
|
|
3
2
|
import { OutputBox } from '@rosen-bridge/scanner-interfaces';
|
|
4
3
|
|
|
5
4
|
import {
|
|
@@ -52,7 +51,7 @@ describe('AbstractErgoExtractor', () => {
|
|
|
52
51
|
expect(extractSpy).toBeCalledWith(
|
|
53
52
|
tx.outputs[0],
|
|
54
53
|
[tx.inputs[0].extension, {}],
|
|
55
|
-
{}
|
|
54
|
+
{},
|
|
56
55
|
);
|
|
57
56
|
expect(storeSpy).toBeCalledWith([extractedData], block, 'Test');
|
|
58
57
|
expect(result).toEqual(true);
|
|
@@ -104,7 +103,7 @@ describe('AbstractErgoExtractor', () => {
|
|
|
104
103
|
{ boxId: tx.inputs[1].boxId, txId: tx.id, index: 2 },
|
|
105
104
|
],
|
|
106
105
|
block,
|
|
107
|
-
'Test'
|
|
106
|
+
'Test',
|
|
108
107
|
);
|
|
109
108
|
expect(result).toEqual(true);
|
|
110
109
|
expect(triggerCallbacks).toBeCalledWith(CallbackType.Spend, [
|
|
@@ -204,7 +203,7 @@ describe('AbstractErgoExtractor', () => {
|
|
|
204
203
|
const insertCallback = vitest.fn();
|
|
205
204
|
const id = await extractor.hook(CallbackType.Insert, insertCallback);
|
|
206
205
|
expect(extractor['callbacks'][CallbackType.Insert]).toEqual(
|
|
207
|
-
new Map().set(id, insertCallback)
|
|
206
|
+
new Map().set(id, insertCallback),
|
|
208
207
|
);
|
|
209
208
|
});
|
|
210
209
|
});
|
|
@@ -229,7 +228,7 @@ describe('AbstractErgoExtractor', () => {
|
|
|
229
228
|
const result = await extractor.unhook(CallbackType.Insert, id);
|
|
230
229
|
expect(result).toBeTruthy();
|
|
231
230
|
expect(extractor['callbacks'][CallbackType.Insert].get(id)).toEqual(
|
|
232
|
-
undefined
|
|
231
|
+
undefined,
|
|
233
232
|
);
|
|
234
233
|
});
|
|
235
234
|
|
|
@@ -253,10 +252,10 @@ describe('AbstractErgoExtractor', () => {
|
|
|
253
252
|
const result = await extractor.unhook(CallbackType.Update, id);
|
|
254
253
|
expect(result).toBeFalsy();
|
|
255
254
|
expect(extractor['callbacks'][CallbackType.Insert].get(id)).toEqual(
|
|
256
|
-
insertCallback
|
|
255
|
+
insertCallback,
|
|
257
256
|
);
|
|
258
257
|
expect(extractor['callbacks'][CallbackType.Update].get(id)).toEqual(
|
|
259
|
-
undefined
|
|
258
|
+
undefined,
|
|
260
259
|
);
|
|
261
260
|
});
|
|
262
261
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataSource } from 'typeorm';
|
|
1
|
+
import { DataSource } from '@rosen-bridge/extended-typeorm';
|
|
2
2
|
import { pick } from 'lodash-es';
|
|
3
3
|
import { BlockInfo } from '@rosen-bridge/scanner-interfaces';
|
|
4
4
|
|
|
@@ -23,7 +23,7 @@ export class TestErgoExtractorAction extends AbstractErgoExtractorAction<
|
|
|
23
23
|
createEntity = (
|
|
24
24
|
boxes: AbstractBoxData[],
|
|
25
25
|
block: BlockInfo,
|
|
26
|
-
extractor: string
|
|
26
|
+
extractor: string,
|
|
27
27
|
): Omit<AbstractErgoExtractorEntity, 'id'>[] => {
|
|
28
28
|
return boxes.map((box) => ({
|
|
29
29
|
boxId: box.boxId,
|
|
@@ -38,7 +38,7 @@ export class TestErgoExtractorAction extends AbstractErgoExtractorAction<
|
|
|
38
38
|
* convert the database entity back to raw data
|
|
39
39
|
*/
|
|
40
40
|
convertEntityToData = (
|
|
41
|
-
entities: AbstractErgoExtractorEntity[]
|
|
41
|
+
entities: AbstractErgoExtractorEntity[],
|
|
42
42
|
): AbstractBoxData[] => {
|
|
43
43
|
return entities.map((data) => pick(data, ['boxId', 'serialized']));
|
|
44
44
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DataSource, Repository } from 'typeorm';
|
|
2
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
1
|
+
import { DataSource, Repository } from '@rosen-bridge/extended-typeorm';
|
|
3
2
|
import { pick } from 'lodash-es';
|
|
4
3
|
|
|
5
4
|
import { TestErgoExtractorAction } from './AbstractErgoExtractorAction.mock';
|
|
@@ -31,7 +30,7 @@ describe('AbstractErgoExtractorAction', () => {
|
|
|
31
30
|
const result = await action.storeBoxes(
|
|
32
31
|
sampleEntities.slice(0, 2),
|
|
33
32
|
block,
|
|
34
|
-
'extractor1'
|
|
33
|
+
'extractor1',
|
|
35
34
|
);
|
|
36
35
|
|
|
37
36
|
const [rows, rowsCount] = await repository.findAndCount();
|
|
@@ -85,7 +84,7 @@ describe('AbstractErgoExtractorAction', () => {
|
|
|
85
84
|
const result = await action.storeBoxes(
|
|
86
85
|
[sampleEntities[0], sampleEntities[1]],
|
|
87
86
|
block,
|
|
88
|
-
'second-extractor'
|
|
87
|
+
'second-extractor',
|
|
89
88
|
);
|
|
90
89
|
|
|
91
90
|
const [insertedRows] = await repository.findAndCount();
|
|
@@ -143,7 +142,7 @@ describe('AbstractErgoExtractorAction', () => {
|
|
|
143
142
|
},
|
|
144
143
|
],
|
|
145
144
|
block,
|
|
146
|
-
'extractor'
|
|
145
|
+
'extractor',
|
|
147
146
|
);
|
|
148
147
|
const [secondInsertRows, secondInsertRowsCount] =
|
|
149
148
|
await repository.findAndCount();
|
|
@@ -184,7 +183,7 @@ describe('AbstractErgoExtractorAction', () => {
|
|
|
184
183
|
const spentBoxIds = await action.spendBoxes(
|
|
185
184
|
spendInfos,
|
|
186
185
|
spendBlock,
|
|
187
|
-
'extractor1'
|
|
186
|
+
'extractor1',
|
|
188
187
|
);
|
|
189
188
|
|
|
190
189
|
const spentBoxes = await repository.findOneBy({
|
|
@@ -225,11 +224,11 @@ describe('AbstractErgoExtractorAction', () => {
|
|
|
225
224
|
|
|
226
225
|
expect(rowsCount).toEqual(2);
|
|
227
226
|
expect(rows.map((row) => row.boxId)).not.toContain(
|
|
228
|
-
sampleEntities.slice(2).map((box) => box.boxId)
|
|
227
|
+
sampleEntities.slice(2).map((box) => box.boxId),
|
|
229
228
|
);
|
|
230
229
|
expect(result).toEqual({
|
|
231
230
|
deletedData: action.convertEntityToData(
|
|
232
|
-
sampleEntities.slice(2) as TestEntity[]
|
|
231
|
+
sampleEntities.slice(2) as TestEntity[],
|
|
233
232
|
),
|
|
234
233
|
updatedData: [],
|
|
235
234
|
});
|
|
@@ -258,7 +257,7 @@ describe('AbstractErgoExtractorAction', () => {
|
|
|
258
257
|
|
|
259
258
|
expect(rowsCount).toEqual(4);
|
|
260
259
|
expect(rows.map((row) => row.boxId)).not.toContain(
|
|
261
|
-
sampleEntities.slice(2).map((box) => box.boxId)
|
|
260
|
+
sampleEntities.slice(2).map((box) => box.boxId),
|
|
262
261
|
);
|
|
263
262
|
expect(result).toEqual({
|
|
264
263
|
deletedData: [],
|
|
@@ -20,24 +20,24 @@ export class MockedInitializableErgoExtractor extends AbstractInitializableErgoE
|
|
|
20
20
|
getId = () => 'Test';
|
|
21
21
|
|
|
22
22
|
hasData = (
|
|
23
|
-
box: V1.OutputInfo | OutputBox // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
23
|
+
box: V1.OutputInfo | OutputBox, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
24
24
|
) => false;
|
|
25
25
|
|
|
26
26
|
getTxBlock = async (
|
|
27
|
-
txId: string // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
27
|
+
txId: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
28
28
|
): Promise<BlockInfo> => {
|
|
29
29
|
return { hash: 'hash', height: 100 };
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
getBoxesWithOffsetLimit = (
|
|
33
33
|
offset: number, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
34
|
-
limit: number // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
34
|
+
limit: number, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
35
35
|
) => {
|
|
36
36
|
return Promise.resolve({ boxes: ergoBoxes, hasNextBatch: true });
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
extractBoxData = (
|
|
40
|
-
box: V1.OutputInfo | OutputBox // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
40
|
+
box: V1.OutputInfo | OutputBox, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
41
41
|
) => {
|
|
42
42
|
return undefined;
|
|
43
43
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { describe, expect, it, vi, vitest } from 'vitest';
|
|
2
1
|
import { ErgoNetworkType } from '@rosen-bridge/scanner-interfaces';
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -29,7 +28,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
29
28
|
const extractor = new MockedInitializableErgoExtractor(
|
|
30
29
|
ErgoNetworkType.Node,
|
|
31
30
|
'node_url',
|
|
32
|
-
'address'
|
|
31
|
+
'address',
|
|
33
32
|
);
|
|
34
33
|
(
|
|
35
34
|
extractor['network'] as NodeNetwork
|
|
@@ -58,7 +57,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
58
57
|
const extractor = new MockedInitializableErgoExtractor(
|
|
59
58
|
ErgoNetworkType.Node,
|
|
60
59
|
'node_url',
|
|
61
|
-
'address'
|
|
60
|
+
'address',
|
|
62
61
|
);
|
|
63
62
|
const processSpy = vitest.fn().mockResolvedValue(true);
|
|
64
63
|
extractor.processTransactions = processSpy;
|
|
@@ -73,7 +72,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
73
72
|
{
|
|
74
73
|
hash: 'b861e2134821fcf1fcdad7e6edd56c4e4495b42b2fd72762a4c79ed1db78b44b',
|
|
75
74
|
height: 1320705,
|
|
76
|
-
}
|
|
75
|
+
},
|
|
77
76
|
);
|
|
78
77
|
});
|
|
79
78
|
|
|
@@ -91,11 +90,11 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
91
90
|
const extractor = new MockedInitializableErgoExtractor(
|
|
92
91
|
ErgoNetworkType.Node,
|
|
93
92
|
'node_url',
|
|
94
|
-
'address'
|
|
93
|
+
'address',
|
|
95
94
|
);
|
|
96
95
|
extractor.processTransactions = vitest.fn().mockResolvedValue(false);
|
|
97
96
|
await expect(() =>
|
|
98
|
-
extractor['processTransactionBatch'](transactionBatch)
|
|
97
|
+
extractor['processTransactionBatch'](transactionBatch),
|
|
99
98
|
).rejects.toThrowError();
|
|
100
99
|
});
|
|
101
100
|
});
|
|
@@ -120,7 +119,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
120
119
|
'node_url',
|
|
121
120
|
'address',
|
|
122
121
|
undefined,
|
|
123
|
-
false
|
|
122
|
+
false,
|
|
124
123
|
);
|
|
125
124
|
const removeSpy = vitest.fn();
|
|
126
125
|
extractor['actions'] = {
|
|
@@ -152,7 +151,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
152
151
|
const extractor = new MockedInitializableErgoExtractor(
|
|
153
152
|
ErgoNetworkType.Node,
|
|
154
153
|
'node_url',
|
|
155
|
-
'address'
|
|
154
|
+
'address',
|
|
156
155
|
);
|
|
157
156
|
const removeSpy = vitest.fn();
|
|
158
157
|
extractor['actions'] = {
|
|
@@ -185,7 +184,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
185
184
|
const extractor = new MockedInitializableErgoExtractor(
|
|
186
185
|
ErgoNetworkType.Node,
|
|
187
186
|
'node_url',
|
|
188
|
-
'address'
|
|
187
|
+
'address',
|
|
189
188
|
);
|
|
190
189
|
const removeSpy = vitest.fn();
|
|
191
190
|
extractor['actions'] = {
|
|
@@ -196,7 +195,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
196
195
|
>;
|
|
197
196
|
const initSpy = vitest.fn().mockRejectedValue(0);
|
|
198
197
|
await expect(
|
|
199
|
-
async () => await extractor['initWithRetrial'](initSpy)
|
|
198
|
+
async () => await extractor['initWithRetrial'](initSpy),
|
|
200
199
|
).rejects.toThrowError();
|
|
201
200
|
expect(removeSpy).toHaveBeenCalledOnce();
|
|
202
201
|
expect(initSpy).toHaveBeenCalledTimes(RETRIAL_COUNT);
|
|
@@ -222,7 +221,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
222
221
|
const extractor = new MockedInitializableErgoExtractor(
|
|
223
222
|
ErgoNetworkType.Node,
|
|
224
223
|
'node_url',
|
|
225
|
-
'address'
|
|
224
|
+
'address',
|
|
226
225
|
);
|
|
227
226
|
(
|
|
228
227
|
extractor['network'] as NodeNetwork
|
|
@@ -256,7 +255,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
256
255
|
const extractor = new MockedInitializableErgoExtractor(
|
|
257
256
|
ErgoNetworkType.Node,
|
|
258
257
|
'node_url',
|
|
259
|
-
'address'
|
|
258
|
+
'address',
|
|
260
259
|
);
|
|
261
260
|
(
|
|
262
261
|
extractor['network'] as NodeNetwork
|
|
@@ -271,7 +270,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
271
270
|
.mockResolvedValue(4);
|
|
272
271
|
extractor['processTransactionBatch'] = vitest.fn();
|
|
273
272
|
expect(() =>
|
|
274
|
-
extractor['initializeWithNode']({ hash: 'hash', height: 1320698 })
|
|
273
|
+
extractor['initializeWithNode']({ hash: 'hash', height: 1320698 }),
|
|
275
274
|
).rejects.toThrowError();
|
|
276
275
|
});
|
|
277
276
|
});
|
|
@@ -300,7 +299,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
300
299
|
const extractor = new MockedInitializableErgoExtractor(
|
|
301
300
|
ErgoNetworkType.Explorer,
|
|
302
301
|
'explorer_url',
|
|
303
|
-
'address'
|
|
302
|
+
'address',
|
|
304
303
|
);
|
|
305
304
|
extractor['initWithRetrial'] = async (job: () => Promise<void>) => job();
|
|
306
305
|
const addressTxSpy = vitest
|
|
@@ -345,7 +344,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
345
344
|
const extractor = new MockedInitializableErgoExtractor(
|
|
346
345
|
ErgoNetworkType.Explorer,
|
|
347
346
|
'explorer_url',
|
|
348
|
-
'address'
|
|
347
|
+
'address',
|
|
349
348
|
);
|
|
350
349
|
// mock `initWithRetrial` to run the job once
|
|
351
350
|
extractor['initWithRetrial'] = async (job: () => Promise<void>) => job();
|
|
@@ -358,7 +357,7 @@ describe('AbstractInitializableErgoExtractor', () => {
|
|
|
358
357
|
if (fromHeight <= 1320000 && toHeight >= 1320000)
|
|
359
358
|
return new Array(100).fill(transactionBatch[0]);
|
|
360
359
|
return [];
|
|
361
|
-
}
|
|
360
|
+
},
|
|
362
361
|
);
|
|
363
362
|
exNetwork.getAddressTransactionsWithHeight = addressTxSpy;
|
|
364
363
|
// spy all other functions to check the calls
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataSource } from 'typeorm';
|
|
1
|
+
import { DataSource } from '@rosen-bridge/extended-typeorm';
|
|
2
2
|
import { pick } from 'lodash-es';
|
|
3
3
|
import { BlockInfo } from '@rosen-bridge/scanner-interfaces';
|
|
4
4
|
|
|
@@ -23,7 +23,7 @@ export class TestInitializableErgoExtractorAction extends AbstractInitializableE
|
|
|
23
23
|
createEntity = (
|
|
24
24
|
boxes: AbstractBoxData[],
|
|
25
25
|
block: BlockInfo,
|
|
26
|
-
extractor: string
|
|
26
|
+
extractor: string,
|
|
27
27
|
): Omit<AbstractErgoExtractorEntity, 'id'>[] => {
|
|
28
28
|
return boxes.map((box) => ({
|
|
29
29
|
boxId: box.boxId,
|
|
@@ -38,7 +38,7 @@ export class TestInitializableErgoExtractorAction extends AbstractInitializableE
|
|
|
38
38
|
* convert the database entity back to raw data
|
|
39
39
|
*/
|
|
40
40
|
convertEntityToData = (
|
|
41
|
-
entities: AbstractErgoExtractorEntity[]
|
|
41
|
+
entities: AbstractErgoExtractorEntity[],
|
|
42
42
|
): AbstractBoxData[] => {
|
|
43
43
|
return entities.map((data) => pick(data, ['boxId', 'serialized']));
|
|
44
44
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DataSource, Repository } from 'typeorm';
|
|
2
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
1
|
+
import { DataSource, Repository } from '@rosen-bridge/extended-typeorm';
|
|
3
2
|
|
|
4
3
|
import { TestInitializableErgoExtractorAction } from './AbstractInitializableAction.mock';
|
|
5
4
|
import { createDatabase, TestEntity } from '../testUtils';
|
|
@@ -51,7 +50,7 @@ describe('AbstractErgoExtractorAction', () => {
|
|
|
51
50
|
sampleEntities.map((entity) => ({
|
|
52
51
|
...entity,
|
|
53
52
|
extractor: 'extractor-new',
|
|
54
|
-
}))
|
|
53
|
+
})),
|
|
55
54
|
);
|
|
56
55
|
const countBefore = await repository.count();
|
|
57
56
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { describe, expect, it, vitest } from 'vitest';
|
|
2
1
|
import ergoExplorerClientFactory from '@rosen-clients/ergo-explorer';
|
|
3
2
|
import { omit } from 'lodash-es';
|
|
4
3
|
|
|
@@ -66,9 +65,8 @@ describe('ExplorerNetwork', () => {
|
|
|
66
65
|
*/
|
|
67
66
|
it('should properly convert explorer api tx to transaction type', async () => {
|
|
68
67
|
const explorerNetwork = new ExplorerNetwork('explorer_url');
|
|
69
|
-
const tx =
|
|
70
|
-
explorerBlockTx
|
|
71
|
-
);
|
|
68
|
+
const tx =
|
|
69
|
+
await explorerNetwork['convertBlockTransaction'](explorerBlockTx);
|
|
72
70
|
expect(tx).toEqual(omit(convertedTx, ['blockId', 'inclusionHeight']));
|
|
73
71
|
});
|
|
74
72
|
});
|
package/tests/testUtils.ts
CHANGED