@rosen-bridge/evm-observation-extractor 5.2.1 → 5.3.0-82c56984

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 (32) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/{BinanceRpcObservationExtractor.d.ts → binanceRpcObservationExtractor.d.ts} +3 -3
  3. package/dist/binanceRpcObservationExtractor.d.ts.map +1 -0
  4. package/dist/binanceRpcObservationExtractor.js +13 -0
  5. package/dist/{EthereumRpcObservationExtractor.d.ts → ethereumRpcObservationExtractor.d.ts} +3 -3
  6. package/dist/ethereumRpcObservationExtractor.d.ts.map +1 -0
  7. package/dist/ethereumRpcObservationExtractor.js +13 -0
  8. package/dist/{EvmRpcObservationExtractor.d.ts → evmRpcObservationExtractor.d.ts} +2 -2
  9. package/dist/evmRpcObservationExtractor.d.ts.map +1 -0
  10. package/dist/evmRpcObservationExtractor.js +60 -0
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +4 -4
  13. package/package.json +25 -17
  14. package/.eslintignore +0 -1
  15. package/dist/BinanceRpcObservationExtractor.d.ts.map +0 -1
  16. package/dist/BinanceRpcObservationExtractor.js +0 -13
  17. package/dist/EthereumRpcObservationExtractor.d.ts.map +0 -1
  18. package/dist/EthereumRpcObservationExtractor.js +0 -13
  19. package/dist/EvmRpcObservationExtractor.d.ts.map +0 -1
  20. package/dist/EvmRpcObservationExtractor.js +0 -59
  21. package/lib/BinanceRpcObservationExtractor.ts +0 -34
  22. package/lib/EthereumRpcObservationExtractor.ts +0 -34
  23. package/lib/EvmRpcObservationExtractor.ts +0 -72
  24. package/lib/index.ts +0 -3
  25. package/tests/EvmRpcObservationExtractor.spec.ts +0 -137
  26. package/tests/TestObservationExtractor.ts +0 -8
  27. package/tests/testData.ts +0 -63
  28. package/tests/utils.mock.ts +0 -130
  29. package/tsconfig.build.json +0 -12
  30. package/tsconfig.build.tsbuildinfo +0 -1
  31. package/tsconfig.json +0 -13
  32. package/vitest.config.ts +0 -18
@@ -1,137 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
- import { vi } from 'vitest';
4
- import { DataSource } from '@rosen-bridge/extended-typeorm';
5
- import { ObservationEntity } from '@rosen-bridge/abstract-observation-extractor';
6
- import { createDatabase, generateBlockEntity } from './utils.mock';
7
- import { expectedObservation, rosenData, tx, txRes } from './testData';
8
- import { TestEvmRpcObservationExtractor } from './TestObservationExtractor';
9
- import { TokenMap } from '@rosen-bridge/tokens';
10
-
11
- vi.mock('ethers', async (importOriginal) => {
12
- const ref = await importOriginal<typeof import('ethers')>();
13
- return {
14
- ...ref,
15
- JsonRpcProvider: vi.fn().mockImplementation(() => {
16
- return {};
17
- }),
18
- };
19
- });
20
-
21
- describe('EvmRpcObservationExtractor', () => {
22
- let dataSource: DataSource;
23
- let extractor: TestEvmRpcObservationExtractor;
24
-
25
- beforeEach(async () => {
26
- dataSource = await createDatabase();
27
- extractor = new TestEvmRpcObservationExtractor(dataSource, new TokenMap(), {
28
- get: vi.fn(),
29
- } as any);
30
- });
31
-
32
- describe('processTransactions', () => {
33
- /**
34
- * @target EvmRpcObservationExtractor.processTransactions
35
- * should return true and insert observation into database on valid lock tx
36
- * @dependencies
37
- * @scenario
38
- * - mock rosen-extractor to return rosen data
39
- * - mock `wait` function of the transaction to return tx object
40
- * - run test
41
- * - check returned value
42
- * - check database
43
- * @expected
44
- * - it should return true
45
- * - observation should be inserted into database
46
- */
47
- it('should return true and insert observation into database on valid lock tx', async () => {
48
- vi.spyOn(extractor.getRosenExtractor(), 'get').mockReturnValue(rosenData);
49
-
50
- vi.spyOn(txRes, 'wait').mockReturnValue(tx as any);
51
-
52
- // run test
53
- const res = await extractor.processTransactions(
54
- [txRes],
55
- generateBlockEntity(dataSource, 'block-id'),
56
- );
57
-
58
- // check returned valid
59
- expect(res).toEqual(true);
60
-
61
- // check database
62
- const repository = dataSource.getRepository(ObservationEntity);
63
- const [rows, rowsCount] = await repository.findAndCount();
64
- expect(rowsCount).toEqual(1);
65
- const observation1 = rows[0];
66
- expect(observation1).toEqual(expectedObservation);
67
- }, 100000);
68
-
69
- /**
70
- * @target EvmRpcObservationExtractor.processTransactions
71
- * should return true but insert no tx when transaction is failed
72
- * @dependencies
73
- * @scenario
74
- * - mock rosen-extractor to return rosen data
75
- * - mock `wait` function of the transaction to throw CallException error
76
- * - run test
77
- * - check returned value
78
- * - check database
79
- * @expected
80
- * - it should return true
81
- * - no observation should be inserted into database
82
- */
83
- it('should return true but insert no tx when transaction is failed', async () => {
84
- vi.spyOn(extractor.getRosenExtractor(), 'get').mockReturnValue(rosenData);
85
-
86
- vi.spyOn(txRes, 'wait').mockImplementation(() => {
87
- throw {
88
- code: 'CALL_EXCEPTION',
89
- };
90
- });
91
-
92
- // run test
93
- const res = await extractor.processTransactions(
94
- [txRes],
95
- generateBlockEntity(dataSource, 'block-id'),
96
- );
97
-
98
- // check returned valid
99
- expect(res).toEqual(true);
100
-
101
- // check database
102
- const repository = dataSource.getRepository(ObservationEntity);
103
- const [, rowsCount] = await repository.findAndCount();
104
- expect(rowsCount).toEqual(0);
105
- }, 100000);
106
-
107
- /**
108
- * @target EvmRpcObservationExtractor.processTransactions
109
- * should return true with no observation in database on invalid lock tx
110
- * @dependencies
111
- * @scenario
112
- * - mock rosen-extractor to return undefined
113
- * - run test
114
- * - check returned value
115
- * - check database
116
- * @expected
117
- * - it should return true
118
- * - no observation should be into database
119
- */
120
- it('should return true with no observation in database on invalid lock tx', async () => {
121
- vi.spyOn(extractor.getRosenExtractor(), 'get').mockReturnValue(undefined);
122
-
123
- const res = await extractor.processTransactions(
124
- [txRes],
125
- generateBlockEntity(dataSource, 'block-id'),
126
- );
127
-
128
- // check returned valid
129
- expect(res).toEqual(true);
130
-
131
- // check database
132
- const repository = dataSource.getRepository(ObservationEntity);
133
- const [, rowsCount] = await repository.findAndCount();
134
- expect(rowsCount).toEqual(0);
135
- }, 100000);
136
- });
137
- });
@@ -1,8 +0,0 @@
1
- import { EvmRpcObservationExtractor } from '../lib';
2
-
3
- export class TestEvmRpcObservationExtractor extends EvmRpcObservationExtractor {
4
- readonly FROM_CHAIN = 'test-chain';
5
-
6
- getId = () => 'test-observation-extractor';
7
- getRosenExtractor = () => this.extractor;
8
- }
package/tests/testData.ts DELETED
@@ -1,63 +0,0 @@
1
- import { blake2b } from 'blakejs';
2
- import {
3
- JsonRpcProvider,
4
- Transaction,
5
- TransactionResponse,
6
- TransactionResponseParams,
7
- } from 'ethers';
8
-
9
- export const tx = Transaction.from({
10
- type: 2,
11
- to: '0xeDee4752e5a2F595151c94762fB38e5730357785',
12
- data: '0xa9059cbb0000000000000000000000004f0d2dde80b45e24ad4019a5aabd6c23aff2842b00000000000000000000000000000000000000000000000000000000e319aa30bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
13
- nonce: 53,
14
- gasLimit: '21000',
15
- gasPrice: null,
16
- maxPriorityFeePerGas: '500000000',
17
- maxFeePerGas: '48978500000',
18
- value: '0',
19
- chainId: '1',
20
- accessList: [],
21
- signature: {
22
- r: '0xc15a4d9e300114ed005a2821f01f4aa74dcfd3daf10749f26d8cc1bd8507673c',
23
- s: '0x090492307ff4c7d2d514f373fa8fb01212c6af83391b6aed7039a3c9d6ecad11',
24
- yParity: 0,
25
- },
26
- hash: '0x3b194eea7cf9507e745806265738ca19213be209885534161ec0fa9c232c9fea',
27
- });
28
- export const txRes = new TransactionResponse(
29
- tx as unknown as TransactionResponseParams,
30
- new JsonRpcProvider(),
31
- );
32
-
33
- export const rosenData = {
34
- toChain: 'to-chain',
35
- toAddress: 'to-address',
36
- bridgeFee: '1968503938',
37
- networkFee: '9842520',
38
- fromAddress: 'from-address',
39
- sourceChainTokenId: 'source-token-id',
40
- amount: '3000000000',
41
- targetChainTokenId: 'target-token-id',
42
- sourceTxId:
43
- '0x3b194eea7cf9507e745806265738ca19213be209885534161ec0fa9c232c9fea',
44
- };
45
-
46
- export const expectedObservation = {
47
- id: 1,
48
- fromChain: 'test-chain',
49
- toChain: rosenData.toChain,
50
- fromAddress: rosenData.fromAddress,
51
- toAddress: rosenData.toAddress,
52
- height: 1,
53
- amount: rosenData.amount,
54
- networkFee: rosenData.networkFee,
55
- bridgeFee: rosenData.bridgeFee,
56
- sourceChainTokenId: rosenData.sourceChainTokenId,
57
- targetChainTokenId: rosenData.targetChainTokenId,
58
- sourceBlockId: 'block-id',
59
- sourceTxId: tx.hash!,
60
- block: 'block-id',
61
- requestId: Buffer.from(blake2b(tx.hash!, undefined, 32)).toString('hex'),
62
- extractor: 'test-observation-extractor',
63
- };
@@ -1,130 +0,0 @@
1
- import { DataSource } from '@rosen-bridge/extended-typeorm';
2
- import {
3
- ObservationEntity,
4
- migrations,
5
- } from '@rosen-bridge/abstract-observation-extractor';
6
- import {
7
- migrations as scannerMigrations,
8
- BlockEntity,
9
- } from '@rosen-bridge/abstract-scanner';
10
-
11
- const fromAddress =
12
- 'addr_test1vzg07d2qp3xje0w77f982zkhqey50gjxrsdqh89yx8r7nasu97hr0';
13
-
14
- export const cardanoTxValid = {
15
- block_hash: '',
16
- metadata: {
17
- '0': JSON.parse(
18
- '{' +
19
- '"to": "ergo",' +
20
- '"bridgeFee": "10000",' +
21
- '"networkFee": "10000",' +
22
- '"toAddress": "ergoAddress",' +
23
- ' "fromAddress": ["' +
24
- fromAddress +
25
- '"] }',
26
- ),
27
- },
28
- tx_hash: '9f00d372e930d685c3b410a10f2bd035cd9a927c4fd8ef8e419c79b210af7ba6',
29
- inputs: [
30
- {
31
- payment_addr: {
32
- bech32:
33
- 'addr_test1vzg07d2qp3xje0w77f982zkhqey50gjxrsdqh89yx8r7nasu97hr0',
34
- cred: '90ff35400c4d2cbddef24a750ad7064947a2461c1a0b9ca431c7e9f6',
35
- },
36
- stake_addr: null,
37
- tx_hash:
38
- '9f00d372e930d685c3b410a10f2bd035cd9a927c4fd8ef8e419c79b210af7ba6',
39
- tx_index: 1,
40
- value: '979445417',
41
- asset_list: [
42
- {
43
- policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
44
- asset_name: '646f6765',
45
- quantity: '10000000',
46
- },
47
- {
48
- policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
49
- asset_name: '7369676d61',
50
- quantity: '9999978',
51
- },
52
- ],
53
- },
54
- ],
55
- outputs: [
56
- {
57
- payment_addr: {
58
- bech32:
59
- 'addr_test1vze7yqqlg8cjlyhz7jzvsg0f3fhxpuu6m3llxrajfzqecggw704re',
60
- cred: 'b3e2001f41f12f92e2f484c821e98a6e60f39adc7ff30fb248819c21',
61
- },
62
- tx_hash:
63
- 'cf32ad374daefdce563e3391effc4fc42eb0e74bbec8afe16a46eeea69e3b2aa',
64
- stake_addr: null,
65
- tx_index: 0,
66
- value: '10000000',
67
- asset_list: [
68
- {
69
- policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
70
- asset_name: '7369676d61',
71
- quantity: '10',
72
- },
73
- ],
74
- },
75
- {
76
- payment_addr: {
77
- bech32:
78
- 'addr_test1vzg07d2qp3xje0w77f982zkhqey50gjxrsdqh89yx8r7nasu97hr0',
79
- cred: '90ff35400c4d2cbddef24a750ad7064947a2461c1a0b9ca431c7e9f6',
80
- },
81
- tx_hash:
82
- 'cf32ad374daefdce563e3391effc4fc42eb0e74bbec8afe16a46eeea69e3b2aa',
83
- stake_addr: null,
84
- tx_index: 1,
85
- value: '969261084',
86
- asset_list: [
87
- {
88
- policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
89
- asset_name: '646f6765',
90
- quantity: '10000000',
91
- },
92
- {
93
- policy_id: 'ace7bcc2ce705679149746620de3a84660ce57573df54b5a096e39a2',
94
- asset_name: '7369676d61',
95
- quantity: '9999968',
96
- },
97
- ],
98
- },
99
- ],
100
- };
101
-
102
- export const createDatabase = async (): Promise<DataSource> => {
103
- return new DataSource({
104
- type: 'sqlite',
105
- database: `:memory:`,
106
- entities: [BlockEntity, ObservationEntity],
107
- migrations: [...migrations.sqlite, ...scannerMigrations.sqlite],
108
- synchronize: false,
109
- logging: false,
110
- })
111
- .initialize()
112
- .then(async (dataSource) => {
113
- await dataSource.runMigrations();
114
- return dataSource;
115
- });
116
- };
117
-
118
- export const generateBlockEntity = (
119
- dataSource: DataSource,
120
- hash: string,
121
- parent?: string,
122
- height?: number,
123
- ) => {
124
- const repository = dataSource.getRepository(BlockEntity);
125
- return repository.create({
126
- height: height ? height : 1,
127
- parentHash: parent ? parent : '1',
128
- hash: hash,
129
- });
130
- };
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./lib"
5
- },
6
- "exclude": ["tests", "vitest.config.ts"],
7
- "references": [
8
- { "path": "../../abstract-observation-extractor" },
9
- { "path": "../../scanners/evm-scanner/tsconfig.build.json" },
10
- { "path": "../../scanner-interfaces/tsconfig.build.json" }
11
- ]
12
- }