-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Add-CommitmentTx.getInstance-and-CommitmentTx.newBuilde…
…r' into 'dev' implement getInstance and newBuilder methods and unit tests Closes #159 See merge request ergo/rosen-bridge/watcher!158
- Loading branch information
Showing
6 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ bin | |
.DS_Store | ||
.env | ||
yarn.lock | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './commitmentTx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/transactions/commitment-tx/tests/commitmentTx.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ObservationEntity } from '@rosen-bridge/observation-extractor'; | ||
import { RWTRepo } from '@rosen-bridge/rwt-repo'; | ||
import { ErgoNetworkType } from '@rosen-bridge/scanner'; | ||
import { blake2b } from 'blakejs'; | ||
import * as ergoLib from 'ergo-lib-wasm-nodejs'; | ||
|
||
export const commitmentTxParams = { | ||
permitAddress: | ||
'EE7687i4URb4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h9M7gcjpr1dUjGMCWxjir94ejfq24XQrSscrZuUT5NVHTWAkzQ', | ||
rwt: '3825b2b4acaaaba626440113153246c65ddb2e9df406c4a56418b5842c9f839a', | ||
txFee: '50', | ||
rwtRepo: new RWTRepo( | ||
'5qwczr7KdspNWq5dg6FZJZSDJ9YGcYDsCVi53E6M9gPamGjQTee9Zp5HLbJXQvWJ49ksh9Ao9YK3VcjHZjVVN2rP74YoYUwCo1xY25jJQRvmqF7tMJdUYAWxB1mg3U5xrcYy6oKhev7TNtnzgWW9831r6yx5B9jmBDj7FoC36s8y7DeKQPsG1HaZLBnyLyR8iKWRUeASSFg8QXMksZdE1ZgsnF218aEmjbeEmnj2DcjwQgatAhJKRzN24PNStzk2D41UL3Xe5FSTyVw7p3u6vXim2hDSKj3qAcGboaVv9SKayhbezzdYxiuKodcyggY63H39cUhgYFwHWahpNhVZBjWP4Q4yAm7ebxjfF2RFFjW8njZNGS1SERo5dqRZZcQ79faKeXmNkZ47TnHB8qQHhwxg4BVEWppfWUyoTbSFdBHGxZufej126i8P3QZaTT7Wi28iC8HA9xTj8ZT7A5facme2TGCFjVucYjRzPLd8PXHqjPq9hoAvUjRQi9pV6uppFppuhAPoNrCyi8JA2yTEcohaokoYLmRgp86QKW4AgCADJKhTczSoHz5wsDbbzTsGeoajPwPEosM2dDazqBobiuhnX5x1m4iegB4QWYJkeNWxPdXCWgxK3fTqGDhKdS6jja9nKUMtixmaLPrwLF22S61NcifoxwEfgTKT11UnmtGMCXkkTDkcreuGUkhZMAG7Kqy3MeuMvJin8f6fb6Mivr6A6ad6rqKChyPiFWr2YaeVbdeidGbQrW9FfjvYhRrTkwBBMcRac6eazjmVqYbe9Mqy1znj8t5PpdyndoGZHPmSbYo9ZF3ZTbjh9qT3kKPQ6TVc772NGyrYWaupPsbk7MJYTBZ5WWtnHbxQyqSLAEmeq4csX3pr5kcgQCoqkqY3UkgoFRBjsTDFp61FiAc6KdivhAh4AvWB5jAYKfqps6XwgQrCRqifD8XN6k6k41Cs6UeMU5FzH4fMqEwBTDyAsCigVaY7gz3eMdDrARc1Ec23rEYepqtuBeWe2ienoMgYazHwp27DvinbAyppFziYmf1n898UXpNqsD5ctyZxQ54n67mEXUAuYq7nJMEsTQpYSX9P4dh6qP9geDbYRbFwpN27gJG5HwqwhFwk1n4ytVxVrc7nHqUe86c5gPXb1DZTgJc9YC9b3yQhE6gcNk83Yn8vkrHvHXPE7wgzxQHgV1iMBtk8DkoFCBbHcd3X4MTskaSNKYcWgx4QPSf2GAg2xcsgRePe6ZKRuRLqoZ8dJKyZRc911UUxkY7qd4ZaBrp8ymmWy2s3mjbN3CY9uqXTLTdokNVUzdvAcrC8SKUAqbX567RN9TcuE5FmagD7RFpmy6eVME1MWSvdscheeoXWcvMCYPwVAvotnFrsypXmnZHXgEdNLQVsk19iNQKYG7Lxu51msGC7gKmVGaiifzrB', | ||
'32ee5d947cfe8db5480157ffa566b9b7d9faf41fa145c9d00628c7c1599878f6', | ||
'3825b2b4acaaaba626440113153246c65ddb2e9df406c4a56418b5842c9f839a', | ||
ErgoNetworkType.Explorer, | ||
'' | ||
), | ||
permitScriptHash: '', | ||
}; | ||
commitmentTxParams.permitScriptHash = Buffer.from( | ||
blake2b( | ||
Buffer.from( | ||
ergoLib.Address.from_base58(commitmentTxParams.permitAddress) | ||
.to_ergo_tree() | ||
.to_base16_bytes(), | ||
'hex' | ||
), | ||
undefined, | ||
32 | ||
) | ||
).toString('hex'); | ||
|
||
export const observationEntity1 = new ObservationEntity(); | ||
observationEntity1.height = 1; | ||
observationEntity1.amount = '10'; | ||
observationEntity1.extractor = 'observation-extractor'; | ||
observationEntity1.bridgeFee = '100'; | ||
observationEntity1.fromAddress = 'fromAddress'; | ||
observationEntity1.block = 'blockHash'; | ||
observationEntity1.fromChain = 'ergo'; | ||
observationEntity1.networkFee = '1000'; | ||
observationEntity1.sourceBlockId = 'block'; | ||
observationEntity1.sourceTxId = 'txId'; | ||
observationEntity1.sourceChainTokenId = 'sourceToken'; | ||
observationEntity1.toAddress = 'addr1'; | ||
observationEntity1.targetChainTokenId = 'targetToken'; | ||
observationEntity1.toChain = 'cardano'; | ||
observationEntity1.requestId = 'reqId2'; |
76 changes: 76 additions & 0 deletions
76
packages/transactions/commitment-tx/tests/commitmentTx.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { describe, expect, it, beforeEach } from 'vitest'; | ||
import { CommitmentTx } from '../lib'; | ||
import { commitmentTxParams, observationEntity1 } from './commitmentTx.mock'; | ||
|
||
describe('CommitmentTx', () => { | ||
beforeEach(() => { | ||
CommitmentTx['_instance'] = undefined; | ||
}); | ||
|
||
describe('getInstance', () => { | ||
/** | ||
* @target should throw exception when CommitmentTx._instance is not yet | ||
* initialized | ||
* @dependencies | ||
* - None | ||
* @scenario | ||
* - call CommitmentTx.getInstance without calling CommitmentTx.init | ||
* - check CommitmentTx.getInstance to throw an exception | ||
* @expected | ||
* - CommitmentTx.getInstance should throw an exception | ||
*/ | ||
it(`should throw exception when CommitmentTx._instance is not yet | ||
initialized`, async () => { | ||
expect(() => CommitmentTx.getInstance()).toThrowError(); | ||
}); | ||
}); | ||
|
||
describe('newBuilder', () => { | ||
/** | ||
* @target should create a new instance of CommitmentTxBuilder with the set | ||
* properties and passed arguments | ||
* @dependencies | ||
* - None | ||
* @scenario | ||
* - call CommitmentTx.getInstance after calling CommitmentTx.init | ||
* - call CommitmentTx.newBuilder on returned CommitmentTx instance to get a | ||
* new instance of CommitmentTxBuilder | ||
* - check returned CommitmentTxBuilder instance to have correct properties | ||
* set | ||
* @expected | ||
* - returned CommitmentTxBuilder should have correct properties set | ||
*/ | ||
it(`should create a new instance of CommitmentTxBuilder with the set | ||
properties and passed arguments`, async () => { | ||
CommitmentTx.init( | ||
commitmentTxParams.permitAddress, | ||
commitmentTxParams.commitmentAddress, | ||
commitmentTxParams.rwt, | ||
commitmentTxParams.txFee, | ||
commitmentTxParams.rwtRepo | ||
); | ||
|
||
const commitmentTxBuilder = | ||
CommitmentTx.getInstance().newBuilder(observationEntity1); | ||
|
||
expect(commitmentTxBuilder['permitAddress']).toEqual( | ||
commitmentTxParams.permitAddress | ||
); | ||
expect(commitmentTxBuilder['permitScriptHash']).toEqual( | ||
commitmentTxParams.permitScriptHash | ||
); | ||
expect(commitmentTxBuilder['commitmentAddress']).toEqual( | ||
commitmentTxParams.commitmentAddress | ||
); | ||
expect(commitmentTxBuilder['rwt']).toEqual(commitmentTxParams.rwt); | ||
expect(commitmentTxBuilder['txFee']).toEqual(commitmentTxParams.txFee); | ||
expect(commitmentTxBuilder['rwtRepo']).toEqual( | ||
commitmentTxParams.rwtRepo | ||
); | ||
expect(commitmentTxBuilder['observation']).toEqual(observationEntity1); | ||
expect(commitmentTxBuilder['eventId']).toEqual( | ||
observationEntity1.requestId | ||
); | ||
}); | ||
}); | ||
}); |