Skip to content

Commit

Permalink
Merge branch 'master-to-dev' into 'dev'
Browse files Browse the repository at this point in the history
Master to dev

See merge request ergo/rosen-bridge/guard-service!416
  • Loading branch information
zargarzadehm committed Nov 11, 2024
2 parents 8c54c44 + 102dac8 commit d569614
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 7 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# guard-service

## 5.0.3

### Patch Changes

- Fix commitment verification

## 5.0.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "guard-service",
"version": "5.0.2",
"version": "5.0.3",
"description": "",
"main": "dist/src/index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Utils {
Buffer.from(event.sourceChainTokenId),
Buffer.from(event.targetChainTokenId),
Buffer.from(event.sourceBlockId),
Utils.bigIntToUint8Array(BigInt(event.height)),
Utils.bigIntToUint8Array(BigInt(event.sourceChainHeight)),
Buffer.from(WID, 'hex'),
]);
return Buffer.from(blake2b(content, undefined, 32)).toString('hex');
Expand Down
4 changes: 2 additions & 2 deletions tests/event/EventBoxes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ describe('EventBoxes', () => {
});

/**
* @target EventBoxes.getEventValidCommitments should not return serialized when commitment box commit is invalid
* @target EventBoxes.getEventValidCommitments should filter commitments with unexpected commit hash
* @dependencies
* - database
* @scenario
Expand All @@ -444,7 +444,7 @@ describe('EventBoxes', () => {
* @expected
* - it should return one valid commitment
*/
it('should not return serialized when commitment box commit is invalid', async () => {
it('should filter commitments with unexpected commit hash', async () => {
// insert a mocked event into db
const mockedEvent = mockEventTrigger();
const eventId = EventSerializer.getId(mockedEvent.event);
Expand Down
24 changes: 23 additions & 1 deletion tests/utils/Utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Utils from '../../src/utils/Utils';
import * as testData from './testData';

describe('Utils', () => {
describe('convertMnemonicToSecretKey', () => {
/**
* @target Utils.convertMnemonicToSecretKey should return correct secret key
* in hex string fromat from mnemonic
* in hex string format from mnemonic
* @dependencies
* @scenario
* - mock mnemonic and corresponding secret key
Expand All @@ -24,4 +25,25 @@ describe('Utils', () => {
expect(result).toEqual(secret);
});
});

describe('commitmentFromEvent', () => {
/**
* @target Utils.commitmentFromEvent should return commitment successfully
* @dependencies
* @scenario
* - mock event and corresponding commit hash
* - run test
* - verify returned value
* @expected
* - returned value should be expected hash
*/
it('should return commitment successfully', () => {
const result = Utils.commitmentFromEvent(
testData.mockedEventForCommitment,
testData.WID
);

expect(result).toEqual(testData.expectedCommitment);
});
});
});
27 changes: 27 additions & 0 deletions tests/utils/testData.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EventTrigger } from '@rosen-chains/abstract-chain';
import { RevenueEntity } from '../../src/db/entities/revenueEntity';
import { RevenueView } from '../../src/db/entities/revenueView';
import { RevenueHistory } from '../../src/types/api';
Expand Down Expand Up @@ -128,3 +129,29 @@ export const revenueHistory: Array<RevenueHistory> = [
],
},
];

export const mockedEventForCommitment: EventTrigger = {
fromChain: 'ADA',
toChain: 'ERG',
fromAddress: '9i1Jy713XfahaB8oFFm2T9kpM7mzT1F4dMvMZKo7rJPB3U4vNVq',
toAddress: '9hPZKvu48kKkPAwrhDukwVxmNrTAa1vXdSsbDijXVsEEYaUt3x5',
amount: '100000',
bridgeFee: '2520',
networkFee: '10000000',
sourceChainTokenId:
'a5d0d1dd7c9faad78a662b065bf053d7e9b454af446fbd50c3bb2e3ba566e164',
targetChainTokenId:
'1db2acc8c356680e21d4d06ce345b83bdf61a89e6b0475768557e06aeb24709f',
sourceTxId:
'cb459f7f8189d3524e6b7361b55baa40c34a71ec5ac506628736096c7aa66f1a',
sourceBlockId:
'7e3b6c9cf8146cf49c0b255d9a8fbeeeb76bea64345f74edc25f8dfee0473968',
sourceChainHeight: 1212,
height: 120000,
WIDsHash: '02020aa2c82582685925e47d6a274c317694bd17ea33a8c7834241a8ce3f0505',
WIDsCount: 5,
};
export const WID =
'245341e0dda895feca93adbd2db9e643a74c50a1b3702db4c2535f23f1c72e6e';
export const expectedCommitment =
'32d5595a12048a13a7807505b26b11e4eae4c69a0c87c39ff7555600708bd23a';

0 comments on commit d569614

Please sign in to comment.