Skip to content

Commit

Permalink
Merge branch 'refactor/revenues-lock-token' into 'dev'
Browse files Browse the repository at this point in the history
refactor(watcher-service): add token data to revenue api

Closes #207

See merge request ergo/rosen-bridge/watcher!217
  • Loading branch information
vorujack committed Dec 30, 2023
2 parents d2a6482 + 35fc979 commit 4a643da
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 24 deletions.
3 changes: 2 additions & 1 deletion services/watcher/src/ergo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,11 @@ export class ErgoUtils {
}
});
return Promise.all(
revenues.map(async (revenue) => {
revenues.map(async ({ tokenId, ...revenue }) => {
const rowTokens = tokenMap.get(revenue.id) || [];
return {
...revenue,
lockToken: this.tokenDetailByTokenMap(tokenId, revenue.fromChain),
revenues: await ErgoUtils.fillTokensDetails(rowTokens),
};
})
Expand Down
2 changes: 1 addition & 1 deletion services/watcher/tests/api/revenues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('revenueRouter', () => {
*/
it('Revenue endpoint should return correct revenues with fromChain filter', async () => {
// send a request to the endpoint
const res = await request(app).get('/revenue?fromChain=fromChainStar');
const res = await request(app).get('/revenue?fromChain=ergo');

// check the result
expect(res.status).to.eql(200);
Expand Down
10 changes: 5 additions & 5 deletions services/watcher/tests/api/testDataEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const events = [
boxSerialized: 'box',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand Down Expand Up @@ -42,7 +42,7 @@ const events = [
boxSerialized: 'box',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand Down Expand Up @@ -76,7 +76,7 @@ const events = [
boxSerialized: 'box',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand Down Expand Up @@ -110,7 +110,7 @@ const events = [
boxSerialized: 'box2',
block: 'blockID2',
height: 100,
fromChain: 'fromChain',
fromChain: 'cardano',
toChain: 'toChain',
fromAddress: 'fromAddress',
toAddress: 'toAddressStar',
Expand Down Expand Up @@ -144,7 +144,7 @@ const events = [
boxSerialized: 'box',
block: 'blockID',
height: 100,
fromChain: 'fromChain',
fromChain: 'cardano',
toChain: 'toChain',
fromAddress: 'fromAddressStar',
toAddress: 'toAddress',
Expand Down
4 changes: 2 additions & 2 deletions services/watcher/tests/database/mockedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ eventTriggerEntity.networkFee = '1000';
eventTriggerEntity.bridgeFee = '200';
eventTriggerEntity.fromAddress = 'fromAddressStar';
eventTriggerEntity.toAddress = 'toAddress';
eventTriggerEntity.fromChain = 'fromChain';
eventTriggerEntity.fromChain = 'cardano';
eventTriggerEntity.toChain = 'toChain';
eventTriggerEntity.sourceChainTokenId = 'tokenId2';
eventTriggerEntity.targetChainTokenId = 'targetTokenId';
Expand All @@ -211,7 +211,7 @@ newEventTriggerEntity.networkFee = '1000';
newEventTriggerEntity.bridgeFee = '200';
newEventTriggerEntity.fromAddress = 'fromAddress';
newEventTriggerEntity.toAddress = 'toAddressStar';
newEventTriggerEntity.fromChain = 'fromChain';
newEventTriggerEntity.fromChain = 'cardano';
newEventTriggerEntity.toChain = 'toChain';
newEventTriggerEntity.sourceChainTokenId = 'tokenId';
newEventTriggerEntity.targetChainTokenId = 'targetTokenId';
Expand Down
6 changes: 3 additions & 3 deletions services/watcher/tests/ergo/statistics/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('Statistics-Api', () => {
boxId: 'boxIdStatistics',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('Statistics-Api', () => {
boxId: 'boxIdStatistics2',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand All @@ -303,7 +303,7 @@ describe('Statistics-Api', () => {
boxId: 'boxIdStatistics3',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand Down
38 changes: 29 additions & 9 deletions services/watcher/tests/ergo/statistics/mockUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ firstStatisticsEventTrigger.networkFee = '1000';
firstStatisticsEventTrigger.bridgeFee = '200';
firstStatisticsEventTrigger.fromAddress = 'fromAddress';
firstStatisticsEventTrigger.toAddress = 'toAddress';
firstStatisticsEventTrigger.fromChain = 'fromChainStar';
firstStatisticsEventTrigger.fromChain = 'ergo';
firstStatisticsEventTrigger.toChain = 'toChainStar';
firstStatisticsEventTrigger.sourceChainTokenId = 'tokenIdStar';
firstStatisticsEventTrigger.targetChainTokenId = 'targetTokenId';
Expand Down Expand Up @@ -208,14 +208,19 @@ const firstRevenue = {
wid: 'WIDStatistics',
eventId: 'ab59962c20f57d9d59e95f5170ccb3472df4279ad4967e51ba8be9ba75144c7b',
lockHeight: 123457,
fromChain: 'fromChain',
fromChain: 'cardano',
toChain: 'toChain',
fromAddress: 'fromAddress',
toAddress: 'toAddressStar',
amount: '100',
bridgeFee: '200',
networkFee: '1000',
tokenId: 'tokenId',
lockToken: {
decimals: 0,
isNativeToken: false,
name: 'Unsupported token',
tokenId: 'tokenId',
},
lockTxId: 'txId2',
height: 2222,
timestamp: 123456789,
Expand All @@ -242,14 +247,19 @@ const lastRevenue = {
permitTxId: 'txId',
eventId: 'ab59962c20f57d9d59e95f5170ccb3472df4279ad4967e51ba8be9ba75144c7b',
lockHeight: 123457,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
amount: '100',
bridgeFee: '200',
networkFee: '1000',
tokenId: 'tokenIdStar',
lockToken: {
decimals: 0,
isNativeToken: false,
name: 'Unsupported token',
tokenId: 'tokenId',
},
lockTxId: 'txIdStar',
height: null,
timestamp: null,
Expand All @@ -267,14 +277,19 @@ const tokenId2Revenue = {
permitTxId: 'txId',
eventId: 'ab59962c20f57d9d59e95f5170ccb3472df4279ad4967e51ba8be9ba75144c7b',
lockHeight: 123457,
fromChain: 'fromChain',
fromChain: 'cardano',
toChain: 'toChain',
fromAddress: 'fromAddressStar',
toAddress: 'toAddress',
amount: '100',
bridgeFee: '200',
networkFee: '1000',
tokenId: 'tokenId2',
lockToken: {
decimals: 0,
isNativeToken: false,
name: 'Unsupported token',
tokenId: 'tokenId',
},
lockTxId: 'txId',
height: 1111,
timestamp: 123,
Expand All @@ -292,14 +307,19 @@ const secondTokenId2Revenue = {
permitTxId: 'txId',
eventId: 'ab59962c20f57d9d59e95f5170ccb3472df4279ad4967e51ba8be9ba75144c7b',
lockHeight: 123457,
fromChain: 'fromChain',
fromChain: 'cardano',
toChain: 'toChain',
fromAddress: 'fromAddressStar',
toAddress: 'toAddress',
amount: '100',
bridgeFee: '200',
networkFee: '1000',
tokenId: 'tokenId2',
lockToken: {
decimals: 0,
isNativeToken: false,
name: 'Unsupported token',
tokenId: 'tokenId',
},
lockTxId: 'txId',
height: null,
timestamp: null,
Expand Down
6 changes: 3 additions & 3 deletions services/watcher/tests/ergo/statistics/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Statistics', () => {
boxId: 'boxIdStatistics',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('Statistics', () => {
boxId: 'boxIdStatistics2',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand All @@ -173,7 +173,7 @@ describe('Statistics', () => {
boxId: 'boxIdStatistics3',
block: 'blockID',
height: 100,
fromChain: 'fromChainStar',
fromChain: 'ergo',
toChain: 'toChainStar',
fromAddress: 'fromAddress',
toAddress: 'toAddress',
Expand Down

0 comments on commit 4a643da

Please sign in to comment.