@rosen-bridge/abstract-extractor 0.3.0 → 1.0.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 +20 -0
- package/dist/ergo/AbstractErgoExtractor.d.ts +31 -8
- package/dist/ergo/AbstractErgoExtractor.d.ts.map +1 -1
- package/dist/ergo/AbstractErgoExtractor.js +73 -8
- package/dist/ergo/AbstractErgoExtractorAction.d.ts +38 -10
- package/dist/ergo/AbstractErgoExtractorAction.d.ts.map +1 -1
- package/dist/ergo/AbstractErgoExtractorAction.js +134 -1
- package/dist/ergo/AbstractErgoExtractorEntity.d.ts +11 -0
- package/dist/ergo/AbstractErgoExtractorEntity.d.ts.map +1 -0
- package/dist/ergo/AbstractErgoExtractorEntity.js +57 -0
- package/dist/ergo/index.d.ts +1 -0
- package/dist/ergo/index.d.ts.map +1 -1
- package/dist/ergo/index.js +2 -1
- package/dist/ergo/initializable/AbstractInitializable.d.ts +4 -3
- package/dist/ergo/initializable/AbstractInitializable.d.ts.map +1 -1
- package/dist/ergo/initializable/AbstractInitializable.js +9 -5
- package/dist/ergo/initializable/AbstractInitializableAction.d.ts +7 -2
- package/dist/ergo/initializable/AbstractInitializableAction.d.ts.map +1 -1
- package/dist/ergo/initializable/AbstractInitializableAction.js +11 -1
- package/dist/ergo/interfaces.d.ts +21 -7
- package/dist/ergo/interfaces.d.ts.map +1 -1
- package/dist/ergo/interfaces.js +8 -1
- package/lib/ergo/AbstractErgoExtractor.ts +107 -23
- package/lib/ergo/AbstractErgoExtractorAction.ts +187 -18
- package/lib/ergo/AbstractErgoExtractorEntity.ts +28 -0
- package/lib/ergo/index.ts +1 -0
- package/lib/ergo/initializable/AbstractInitializable.ts +22 -9
- package/lib/ergo/initializable/AbstractInitializableAction.ts +19 -3
- package/lib/ergo/interfaces.ts +25 -7
- package/package.json +6 -2
- package/tests/{AbstractExtractor.mock.ts → AbstractErgoExtractor.mock.ts} +12 -7
- package/tests/AbstractErgoExtractor.spec.ts +281 -0
- package/tests/AbstractErgoExtractorAction.mock.ts +45 -0
- package/tests/AbstractErgoExtractorAction.spec.ts +269 -0
- package/tests/initializable/AbstractInitializable.mock.ts +15 -8
- package/tests/initializable/AbstractInitializable.spec.ts +37 -5
- package/tests/initializable/AbstractInitializableAction.mock.ts +45 -0
- package/tests/initializable/AbstractInitializableAction.spec.ts +65 -0
- package/tests/testData.ts +38 -2
- package/tests/testUtils.ts +22 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/ergo/initializable/InitializableByAddress.d.ts +0 -19
- package/dist/ergo/initializable/InitializableByAddress.d.ts.map +0 -1
- package/dist/ergo/initializable/InitializableByAddress.js +0 -30
- package/dist/ergo/initializable/InitializableByToken.d.ts +0 -19
- package/dist/ergo/initializable/InitializableByToken.d.ts.map +0 -1
- package/dist/ergo/initializable/InitializableByToken.js +0 -30
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/tests/AbstractExtractor.spec.ts +0 -106
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { V1 } from '@rosen-clients/ergo-explorer';
|
|
2
|
-
import { describe, it, expect, vitest } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
OutputBox,
|
|
6
|
-
ErgoExtractedData,
|
|
7
|
-
AbstractErgoExtractorAction,
|
|
8
|
-
} from '../lib';
|
|
9
|
-
import { block, extractedData, tx } from './testData';
|
|
10
|
-
import { MockedErgoExtractor } from './AbstractExtractor.mock';
|
|
11
|
-
|
|
12
|
-
describe('AbstractErgoExtractor', () => {
|
|
13
|
-
describe('processTransactions', () => {
|
|
14
|
-
/**
|
|
15
|
-
* @target processTransactions should initialize extractor with specified id and insert status into db
|
|
16
|
-
* @dependencies
|
|
17
|
-
* @scenario
|
|
18
|
-
* - mock extractor
|
|
19
|
-
* - mock `hasData` to return true for one box
|
|
20
|
-
* - spy `extractBoxData` and `insertBoxes`
|
|
21
|
-
* - run test (call `processTransactions`)
|
|
22
|
-
* @expected
|
|
23
|
-
* - to call `extractBoxData` for the specific box
|
|
24
|
-
* - to insert the extracted box to database
|
|
25
|
-
*/
|
|
26
|
-
it('should process boxes with data and insert data into database', async () => {
|
|
27
|
-
const extractor = new MockedErgoExtractor();
|
|
28
|
-
extractor.hasData = (box: V1.OutputInfo | OutputBox) => {
|
|
29
|
-
if (box.boxId == tx.outputs[0].boxId) return true;
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
|
-
const extractSpy = vitest.fn().mockReturnValue(extractedData);
|
|
33
|
-
extractor.extractBoxData = extractSpy;
|
|
34
|
-
const insertSpy = vitest.fn();
|
|
35
|
-
extractor['actions'] = {
|
|
36
|
-
insertBoxes: insertSpy,
|
|
37
|
-
} as unknown as AbstractErgoExtractorAction<ErgoExtractedData>;
|
|
38
|
-
extractor.processTransactions([tx], block);
|
|
39
|
-
|
|
40
|
-
expect(extractSpy).toBeCalledTimes(1);
|
|
41
|
-
expect(extractSpy).toBeCalledWith(
|
|
42
|
-
tx.outputs[0],
|
|
43
|
-
block.hash,
|
|
44
|
-
block.height
|
|
45
|
-
);
|
|
46
|
-
expect(insertSpy).toBeCalledWith([extractedData], 'Test');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @target processTransactions should extract spend info of transaction spend related boxes
|
|
51
|
-
* @dependencies
|
|
52
|
-
* @scenario
|
|
53
|
-
* - mock extractor
|
|
54
|
-
* - spy `extractBoxData`, `insertBoxes` and `spendBoxes`
|
|
55
|
-
* - run test (call `processTransactions`)
|
|
56
|
-
* @expected
|
|
57
|
-
* - not to call `extractBoxData` and `insertBoxes` when there is not any box with data
|
|
58
|
-
* - to extractor spend info of input boxes and call `spendBoxes`
|
|
59
|
-
*/
|
|
60
|
-
it('should extract spend info of transaction spend related boxes', async () => {
|
|
61
|
-
const extractor = new MockedErgoExtractor();
|
|
62
|
-
const extractSpy = vitest.fn();
|
|
63
|
-
extractor.extractBoxData = extractSpy;
|
|
64
|
-
const insertSpy = vitest.fn();
|
|
65
|
-
const spendSpy = vitest.fn();
|
|
66
|
-
extractor['actions'] = {
|
|
67
|
-
insertBoxes: insertSpy,
|
|
68
|
-
spendBoxes: spendSpy,
|
|
69
|
-
} as unknown as AbstractErgoExtractorAction<ErgoExtractedData>;
|
|
70
|
-
extractor.processTransactions([tx], block);
|
|
71
|
-
|
|
72
|
-
expect(extractSpy).not.toBeCalled();
|
|
73
|
-
expect(insertSpy).not.toBeCalled();
|
|
74
|
-
expect(spendSpy).toBeCalledWith(
|
|
75
|
-
[
|
|
76
|
-
{ boxId: tx.inputs[0].boxId, txId: tx.id, index: 1 },
|
|
77
|
-
{ boxId: tx.inputs[1].boxId, txId: tx.id, index: 2 },
|
|
78
|
-
],
|
|
79
|
-
block,
|
|
80
|
-
'Test'
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('forkBlock', () => {
|
|
86
|
-
/**
|
|
87
|
-
* @target forkBlock should remove all data extracted from the specified block
|
|
88
|
-
* @dependencies
|
|
89
|
-
* @scenario
|
|
90
|
-
* - mock extractor
|
|
91
|
-
* - spy `deleteBlockBoxes`
|
|
92
|
-
* - run test (call `forkBlock`)
|
|
93
|
-
* @expected
|
|
94
|
-
* - to call `deleteBlockBoxes` for the specific box
|
|
95
|
-
*/
|
|
96
|
-
it('should remove all data extracted from the specified block', async () => {
|
|
97
|
-
const extractor = new MockedErgoExtractor();
|
|
98
|
-
const removeSpy = vitest.fn();
|
|
99
|
-
extractor['actions'] = {
|
|
100
|
-
deleteBlockBoxes: removeSpy,
|
|
101
|
-
} as unknown as AbstractErgoExtractorAction<ErgoExtractedData>;
|
|
102
|
-
extractor.forkBlock(block.hash);
|
|
103
|
-
expect(removeSpy).toBeCalledWith(block.hash, 'Test');
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|