@rosen-bridge/abstract-extractor 0.3.1 → 1.0.1-27579971

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/ergo/AbstractErgoExtractor.d.ts +30 -5
  3. package/dist/ergo/AbstractErgoExtractor.d.ts.map +1 -1
  4. package/dist/ergo/AbstractErgoExtractor.js +72 -7
  5. package/dist/ergo/AbstractErgoExtractorAction.d.ts +37 -10
  6. package/dist/ergo/AbstractErgoExtractorAction.d.ts.map +1 -1
  7. package/dist/ergo/AbstractErgoExtractorAction.js +134 -1
  8. package/dist/ergo/AbstractErgoExtractorEntity.d.ts +11 -0
  9. package/dist/ergo/AbstractErgoExtractorEntity.d.ts.map +1 -0
  10. package/dist/ergo/AbstractErgoExtractorEntity.js +57 -0
  11. package/dist/ergo/index.d.ts +1 -0
  12. package/dist/ergo/index.d.ts.map +1 -1
  13. package/dist/ergo/index.js +2 -1
  14. package/dist/ergo/initializable/AbstractInitializable.d.ts +4 -3
  15. package/dist/ergo/initializable/AbstractInitializable.d.ts.map +1 -1
  16. package/dist/ergo/initializable/AbstractInitializable.js +9 -5
  17. package/dist/ergo/initializable/AbstractInitializableAction.d.ts +7 -2
  18. package/dist/ergo/initializable/AbstractInitializableAction.d.ts.map +1 -1
  19. package/dist/ergo/initializable/AbstractInitializableAction.js +11 -1
  20. package/dist/ergo/interfaces.d.ts +24 -1
  21. package/dist/ergo/interfaces.d.ts.map +1 -1
  22. package/dist/ergo/interfaces.js +8 -1
  23. package/dist/ergo/network/ExplorerNetwork.d.ts.map +1 -1
  24. package/dist/ergo/network/ExplorerNetwork.js +3 -1
  25. package/dist/ergo/network/NodeNetwork.d.ts.map +1 -1
  26. package/dist/ergo/network/NodeNetwork.js +2 -1
  27. package/lib/ergo/AbstractErgoExtractor.ts +105 -12
  28. package/lib/ergo/AbstractErgoExtractorAction.ts +185 -18
  29. package/lib/ergo/AbstractErgoExtractorEntity.ts +28 -0
  30. package/lib/ergo/index.ts +1 -0
  31. package/lib/ergo/initializable/AbstractInitializable.ts +22 -9
  32. package/lib/ergo/initializable/AbstractInitializableAction.ts +19 -3
  33. package/lib/ergo/interfaces.ts +29 -1
  34. package/lib/ergo/network/ExplorerNetwork.ts +2 -0
  35. package/lib/ergo/network/NodeNetwork.ts +2 -1
  36. package/package.json +8 -4
  37. package/tests/{AbstractExtractor.mock.ts → AbstractErgoExtractor.mock.ts} +11 -4
  38. package/tests/AbstractErgoExtractor.spec.ts +281 -0
  39. package/tests/AbstractErgoExtractorAction.mock.ts +45 -0
  40. package/tests/AbstractErgoExtractorAction.spec.ts +269 -0
  41. package/tests/initializable/AbstractInitializable.mock.ts +14 -3
  42. package/tests/initializable/AbstractInitializable.spec.ts +37 -5
  43. package/tests/initializable/AbstractInitializableAction.mock.ts +45 -0
  44. package/tests/initializable/AbstractInitializableAction.spec.ts +65 -0
  45. package/tests/network/testData.ts +11 -18
  46. package/tests/testData.ts +38 -0
  47. package/tests/testUtils.ts +22 -0
  48. package/tsconfig.build.tsbuildinfo +1 -1
  49. package/dist/ergo/initializable/InitializableByAddress.d.ts +0 -19
  50. package/dist/ergo/initializable/InitializableByAddress.d.ts.map +0 -1
  51. package/dist/ergo/initializable/InitializableByAddress.js +0 -30
  52. package/dist/ergo/initializable/InitializableByToken.d.ts +0 -19
  53. package/dist/ergo/initializable/InitializableByToken.d.ts.map +0 -1
  54. package/dist/ergo/initializable/InitializableByToken.js +0 -30
  55. package/dist/tsconfig.tsbuildinfo +0 -1
  56. package/tests/AbstractExtractor.spec.ts +0 -102
@@ -0,0 +1,45 @@
1
+ import { DataSource } from 'typeorm';
2
+ import { pick } from 'lodash-es';
3
+
4
+ import {
5
+ AbstractErgoExtractorEntity,
6
+ BlockInfo,
7
+ AbstractBoxData,
8
+ AbstractInitializableErgoExtractorAction,
9
+ } from '../../lib';
10
+ import { TestEntity } from '../testUtils';
11
+
12
+ export class TestInitializableErgoExtractorAction extends AbstractInitializableErgoExtractorAction<
13
+ AbstractBoxData,
14
+ AbstractErgoExtractorEntity
15
+ > {
16
+ constructor(dataSource: DataSource) {
17
+ super(dataSource, TestEntity);
18
+ }
19
+
20
+ /**
21
+ * create the test database entity from data and block information
22
+ */
23
+ createEntity = (
24
+ boxes: AbstractBoxData[],
25
+ block: BlockInfo,
26
+ extractor: string
27
+ ): Omit<AbstractErgoExtractorEntity, 'id'>[] => {
28
+ return boxes.map((box) => ({
29
+ boxId: box.boxId,
30
+ block: block.hash,
31
+ height: block.height,
32
+ serialized: box.serialized,
33
+ extractor: extractor,
34
+ }));
35
+ };
36
+
37
+ /**
38
+ * convert the database entity back to raw data
39
+ */
40
+ convertEntityToData = (
41
+ entities: AbstractErgoExtractorEntity[]
42
+ ): AbstractBoxData[] => {
43
+ return entities.map((data) => pick(data, ['boxId', 'serialized']));
44
+ };
45
+ }
@@ -0,0 +1,65 @@
1
+ import { DataSource, Repository } from 'typeorm';
2
+ import { describe, it, expect, beforeEach } from 'vitest';
3
+
4
+ import { TestInitializableErgoExtractorAction } from './AbstractInitializableAction.mock';
5
+ import { createDatabase, TestEntity } from '../testUtils';
6
+ import { sampleEntities } from '../testData';
7
+
8
+ describe('AbstractErgoExtractorAction', () => {
9
+ let dataSource: DataSource;
10
+ let action: TestInitializableErgoExtractorAction;
11
+ let repository: Repository<TestEntity>;
12
+ beforeEach(async () => {
13
+ dataSource = await createDatabase();
14
+ action = new TestInitializableErgoExtractorAction(dataSource);
15
+ repository = dataSource.getRepository(TestEntity);
16
+ });
17
+
18
+ describe('removeAllData', () => {
19
+ /**
20
+ * @target removeAllData should remove all available data related to this extractor
21
+ * @dependencies
22
+ * @scenario
23
+ * - insert 4 entities related to this extractor
24
+ * - run test (call `removeAllData`)
25
+ * @expected
26
+ * - to have 4 entities before removing
27
+ * - to have no remaining entities after remove
28
+ */
29
+ it(`should remove all available data related to this extractor`, async () => {
30
+ await dataSource.getRepository(TestEntity).insert(sampleEntities);
31
+ const countBefore = await repository.count();
32
+
33
+ await action.removeAllData('extractor');
34
+ const countAfter = await repository.count();
35
+
36
+ expect(countBefore).toEqual(4);
37
+ expect(countAfter).toEqual(0);
38
+ });
39
+
40
+ /**
41
+ * @target removeAllData should not remove any data related to another extractor
42
+ * @dependencies
43
+ * @scenario
44
+ * - insert 4 entities related to another extractor
45
+ * - run test (call `removeAllData`)
46
+ * @expected
47
+ * - to have 4 entities after removing
48
+ */
49
+ it(`should not remove any data related to another extractor`, async () => {
50
+ await dataSource.getRepository(TestEntity).insert(
51
+ sampleEntities.map((entity) => ({
52
+ ...entity,
53
+ extractor: 'extractor-new',
54
+ }))
55
+ );
56
+ const countBefore = await repository.count();
57
+
58
+ await action.removeAllData('extractor');
59
+ const countAfter = await repository.count();
60
+
61
+ expect(countBefore).toEqual(4);
62
+ expect(countAfter).toEqual(4);
63
+ });
64
+ });
65
+ });
@@ -1240,7 +1240,7 @@ export const nodeTx = {
1240
1240
  timestamp: 1722500537020n,
1241
1241
  index: 3,
1242
1242
  globalIndex: 7582283n,
1243
- numConfirmations: 0,
1243
+ numConfirmations: 146428,
1244
1244
  inputs: [
1245
1245
  {
1246
1246
  globalIndex: 41863807n,
@@ -1264,17 +1264,11 @@ export const nodeTx = {
1264
1264
  additionalRegisters: {
1265
1265
  R4: '05a686a9ad09',
1266
1266
  R5: '04a299a101',
1267
- },
1267
+ } as Registers,
1268
1268
  transactionId:
1269
1269
  'c1625b2f26935514d9cc47ce3acedb75e7b51595c1a26cc2fe0b6eadeeb205d8',
1270
1270
  index: 0,
1271
- spendingProof: {
1272
- proofBytes:
1273
- '4ab9da11fc216660e974842cc3b7705e62ebb9e0bf5ff78e53f9cd40abadd1173ab9da11fc216660e974842cc3b7705e62ebb9e0bf5ff78e53f9cd40abadd1173ab9da11fc216660e974842cc3b7705e62ebb9e0bf5ff78e53f9cd40abadd117',
1274
- extension: {
1275
- '1': 'a2aed72ff1b139f35d1ad2938cb44c9848a34d4dcfd6d8ab717ebde40a7304f2541cf628ffc8b5c496e6161eba3f169c6dd440704b1719e0',
1276
- },
1277
- },
1271
+ spendingHeight: null,
1278
1272
  },
1279
1273
  {
1280
1274
  globalIndex: 41863813n,
@@ -1292,13 +1286,7 @@ export const nodeTx = {
1292
1286
  transactionId:
1293
1287
  'c1625b2f26935514d9cc47ce3acedb75e7b51595c1a26cc2fe0b6eadeeb205d8',
1294
1288
  index: 6,
1295
- spendingProof: {
1296
- proofBytes:
1297
- '4ab9da11fc216660e974842cc3b7705e62ebb9e0bf5ff78e53f9cd40abadd1173ab9da11fc216660e974842cc3b7705e62ebb9e0bf5ff78e53f9cd40abadd1173ab9da11fc216660e974842cc3b7705e62ebb9e0bf5ff78e53f9cd40abadd117',
1298
- extension: {
1299
- '1': 'a2aed72ff1b139f35d1ad2938cb44c9848a34d4dcfd6d8ab717ebde40a7304f2541cf628ffc8b5c496e6161eba3f169c6dd440704b1719e0',
1300
- },
1301
- },
1289
+ spendingHeight: null,
1302
1290
  },
1303
1291
  ],
1304
1292
  dataInputs: [],
@@ -1308,7 +1296,8 @@ export const nodeTx = {
1308
1296
  inclusionHeight: 1320528,
1309
1297
  address:
1310
1298
  'NTkuk55NdwCXkF1e2nCABxq7bHjtinX3wH13zYPZ6qYT71dCoZBe1gZkh9FAr7GeHo2EpFoibzpNQmoi89atUjKRrhZEYrTapdtXrWU4kq319oY7BEWmtmRU9cMohX69XMuxJjJP5hRM8WQLfFnffbjshhEP3ck9CKVEkFRw1JDYkqVke2JVqoMED5yxLVkScbBUiJJLWq9BSbE1JJmmreNVskmWNxWE6V7ksKPxFMoqh1SVePh3UWAaBgGQRZ7TWf4dTBF5KMVHmRXzmQqEu2Fz2yeSLy23sM3pfqa78VuvoFHnTFXYFFxn3DNttxwq3EU3Zv25SmgrWjLKiZjFcEcqGgH6DJ9FZ1DfucVtTXwyDJutY3ksUBaEStRxoUQyRu4EhDobixL3PUWRcxaRJ8JKA9b64ALErGepRHkAoVmS8DaE6VbroskyMuhkTo7LbrzhTyJbqKurEzoEfhYxus7bMpLTePgKcktgRRyB7MjVxjSpxWzZedvzbjzZaHLZLkWZESk1WtdM25My33wtVLNXiTvficEUbjA23sNd24pv1YQ72nY1aqUHa2',
1311
- spentTransactionId: null,
1299
+ spentTransactionId:
1300
+ '0ad32fd0423a4d2e551f0ae9be28a650bef4b9420791bd5208c6f35c1b234322',
1312
1301
  boxId: '3729892f2fcd5b05761ab2994bb418947a5e7d6aaeae5c46351b2e6cf29afc34',
1313
1302
  value: 5810250000n,
1314
1303
  ergoTree:
@@ -1329,6 +1318,7 @@ export const nodeTx = {
1329
1318
  transactionId:
1330
1319
  '4e7c782db6525e7d59a28df3b72a16d26fcb64ceae535dfec3936e61d8feddf2',
1331
1320
  index: 0,
1321
+ spendingHeight: null,
1332
1322
  },
1333
1323
  {
1334
1324
  globalIndex: 41864032n,
@@ -1347,12 +1337,14 @@ export const nodeTx = {
1347
1337
  transactionId:
1348
1338
  '4e7c782db6525e7d59a28df3b72a16d26fcb64ceae535dfec3936e61d8feddf2',
1349
1339
  index: 1,
1340
+ spendingHeight: null,
1350
1341
  },
1351
1342
  {
1352
1343
  globalIndex: 41864033n,
1353
1344
  inclusionHeight: 1320528,
1354
1345
  address: '9fzRcctiWfzoJyqGtPWqoXPuxSmFw6zpnjtsQ1B6jSN514XqH4q',
1355
- spentTransactionId: null,
1346
+ spentTransactionId:
1347
+ 'fc362346389ebad8252c19a6489a5c55eb3afbca4b9e21cc1c8aa4583d1aefd3',
1356
1348
  boxId: '918c7a92bf9ab9ba45cb96df067129f3fc0c24b62bf91d7f8c7f1d3062e52426',
1357
1349
  value: 23324978571n,
1358
1350
  ergoTree:
@@ -1363,6 +1355,7 @@ export const nodeTx = {
1363
1355
  transactionId:
1364
1356
  '4e7c782db6525e7d59a28df3b72a16d26fcb64ceae535dfec3936e61d8feddf2',
1365
1357
  index: 2,
1358
+ spendingHeight: null,
1366
1359
  },
1367
1360
  ],
1368
1361
  size: 789,
package/tests/testData.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Block } from '../lib';
2
+ import { TestEntity } from './testUtils';
2
3
 
3
4
  export const tx = {
4
5
  id: '3b91fbd2b6f4f3f971098655ffa320841001b071908de057cdf8c425cd3b3e61',
@@ -107,3 +108,40 @@ export const block: Block = {
107
108
  height: 100,
108
109
  parentHash: 'parentHash',
109
110
  } as Block;
111
+
112
+ export const block2: Block = {
113
+ hash: 'hash2',
114
+ height: 101,
115
+ parentHash: 'parentHash2',
116
+ } as Block;
117
+
118
+ export const sampleEntities: Omit<TestEntity, 'id'>[] = [
119
+ {
120
+ extractor: 'extractor',
121
+ boxId: '1',
122
+ serialized: 'serialized1',
123
+ block: 'blockId1',
124
+ height: 100,
125
+ },
126
+ {
127
+ extractor: 'extractor',
128
+ boxId: '2',
129
+ serialized: 'serialized2',
130
+ block: 'blockId2',
131
+ height: 200,
132
+ },
133
+ {
134
+ extractor: 'extractor',
135
+ boxId: '3',
136
+ serialized: 'serialized3',
137
+ block: 'blockId3',
138
+ height: 300,
139
+ },
140
+ {
141
+ extractor: 'extractor',
142
+ boxId: '4',
143
+ serialized: 'serialized4',
144
+ block: 'blockId4',
145
+ height: 400,
146
+ },
147
+ ];
@@ -0,0 +1,22 @@
1
+ import { DataSource, Entity } from 'typeorm';
2
+ import { AbstractErgoExtractorEntity } from '../lib';
3
+
4
+ @Entity('test_entity')
5
+ export class TestEntity extends AbstractErgoExtractorEntity {}
6
+
7
+ /**
8
+ * generates a dataSource with in memory database for testing
9
+ */
10
+ export const createDatabase = async (): Promise<DataSource> => {
11
+ const dataSource = new DataSource({
12
+ type: 'sqlite',
13
+ database: `:memory:`,
14
+ entities: [TestEntity],
15
+ migrations: [],
16
+ synchronize: true,
17
+ logging: false,
18
+ });
19
+ await dataSource.initialize();
20
+ await dataSource.runMigrations();
21
+ return dataSource;
22
+ };