Skip to content

Commit

Permalink
fix/gap-expiration-time: fixed expiration time of GAPs
Browse files Browse the repository at this point in the history
  • Loading branch information
BEdev24 committed Dec 13, 2024
1 parent 7aff02c commit 6dd66d0
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class GovActionProposalRequest {
govActionType: string;
govMetadataUrl: string;
status: string;
endTime: Date;
txHash: string;
submitTime: Date;
}
1 change: 1 addition & 0 deletions worker-service/src/governance/dto/vote.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class VoteRequest {
govActionType: string;
govMetadataUrl: string;
status: string;
endTime: Date;
txHash: string;
govActionProposalSubmitTime: Date;
}
14 changes: 14 additions & 0 deletions worker-service/src/governance/facade/governance.facade.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('GovernanceFacade', () => {
'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
status: 'DROPPED',
submitTime: new Date('2024-05-21 15:18:06.000'),
endTime: new Date('2024-05-26T22:29:45.000Z'),
txHash:
'D775FBCB6006524ABBFFE6DAF538E71941745B44A3A735852FBBD49FD7D59A95',
},
Expand All @@ -38,6 +39,7 @@ describe('GovernanceFacade', () => {
'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
status: 'DROPPED',
submitTime: new Date('2024-05-21 17:08:38.000'),
endTime: new Date('2024-05-26T22:29:45.000Z'),
txHash:
'DB4DBEB5946E5D49778F457D9C5A460488C40AF0B93D8B98111F5BE11BF165A6',
},
Expand All @@ -49,6 +51,7 @@ describe('GovernanceFacade', () => {
'1111111111111111111111111111111111111111111111111111111111111111',
status: 'DROPPED',
submitTime: new Date('2024-05-22 10:08:20.000'),
endTime: new Date('2024-05-27T22:29:38.000Z'),
txHash:
'67820C121787464A9B670CF4C648F67CABD9573EB71B220214971CE467D25027',
},
Expand All @@ -59,6 +62,7 @@ describe('GovernanceFacade', () => {
govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json',
status: 'DROPPED',
submitTime: new Date('2024-05-17 12:56:00.000'),
endTime: new Date('2024-05-17 12:56:00.000'),
txHash:
'69AA81F4AA0140E8D2AB2B6642C403611CD730FAB42E6C9F9E3E15D6D90BD3E9',
},
Expand All @@ -70,6 +74,7 @@ describe('GovernanceFacade', () => {
'https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt',
status: 'DROPPED',
submitTime: new Date('2024-05-17 16:15:34.000'),
endTime: new Date('2024-05-22T22:29:33.000Z'),
txHash:
'EDEF927AF962664ED7A02BEDFA913C7F1CD271494871C25EE7DE66E941D83C79',
},
Expand All @@ -81,6 +86,7 @@ describe('GovernanceFacade', () => {
'https://raw.githubusercontent.com/Sworzen1/Testing-Todo-app/main/Treasury.jsonld',
status: 'DROPPED',
submitTime: new Date('2024-05-27 09:19:00.000'),
endTime: new Date('2024-06-01T22:29:51.000Z'),
txHash:
'2C2F01F6818CEE5E2EC29EF965DF347099173707BAFCEFC7F6FE3D66CD5F66EC',
},
Expand All @@ -92,6 +98,7 @@ describe('GovernanceFacade', () => {
'https://raw.githubusercontent.com/Ryun1/metadata/main/cip100/ga.jsonld',
status: 'DROPPED',
submitTime: new Date('2024-05-27 20:34:28.000'),
endTime: new Date('2024-06-01T22:29:51.000Z'),
txHash:
'3B15AC25580564C8C565121188B142BEE99F6AAD7D4130FFC6A5A764EBA1159A',
},
Expand All @@ -102,6 +109,7 @@ describe('GovernanceFacade', () => {
govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json',
status: 'DROPPED',
submitTime: new Date('2024-05-18 20:25:26.000'),
endTime: new Date('2024-05-23T22:27:46.000Z'),
txHash:
'6A3319F5AC57551C4CABF77D0603BD6C72F44E9D10830363D87EB34CB43AFCB2',
},
Expand All @@ -112,6 +120,7 @@ describe('GovernanceFacade', () => {
govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info',
status: 'DROPPED',
submitTime: new Date('2024-05-18 14:29:22.000'),
endTime: new Date('2024-05-23T22:27:46.000Z'),
txHash:
'B9532421430F6611C0170993E88DFA29B6AA0D4CCE024AD88346C59BE2B65B41',
},
Expand All @@ -122,6 +131,7 @@ describe('GovernanceFacade', () => {
govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info',
status: 'DROPPED',
submitTime: new Date('2024-05-26 04:02:39.000'),
endTime: new Date('2024-05-31T22:29:15.000Z'),
txHash:
'2EC4AD524F0AF3EEB1F05C360BFDECF815936E7CBF8EAC9C07A4E0C7072D03D1',
},
Expand All @@ -135,6 +145,7 @@ describe('GovernanceFacade', () => {
govMetadataUrl: 'https://bit.ly/3zCH2HL',
status: 'DROPPED',
submitTime: new Date('2024-05-20 06:39:16.000'),
endTime: new Date('2024-05-25T22:29:48.000Z'),
txHash:
'cef93aface365b575e1f33987fad4093e2a8a06d31c01a260e0e7db325fc0b50',
},
Expand All @@ -145,6 +156,7 @@ describe('GovernanceFacade', () => {
govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info',
status: 'DROPPED',
submitTime: new Date('2024-05-22 12:24:59.000'),
endTime: new Date('2024-05-27T22:29:38.000Z'),
txHash:
'75d1c676f459f1192c7fd2c73423635a074c5e7b46497e00f44428861f460153',
},
Expand All @@ -156,6 +168,7 @@ describe('GovernanceFacade', () => {
'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
status: 'DROPPED',
submitTime: new Date('2024-05-22 19:47:27.000'),
endTime: new Date('2024-05-27T22:29:38.000Z'),
txHash:
'9bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397',
},
Expand All @@ -167,6 +180,7 @@ describe('GovernanceFacade', () => {
'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
status: 'DROPPED',
submitTime: new Date('2024-05-22 21:44:26.000'),
endTime: new Date('2024-05-27T22:29:38.000Z'),
txHash:
'f6ca72e9fe225c01e1a622d529ad807d668a786cb28d1eb352b8da58b66dd8c2',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class GovActionProposalMapper {
govActionProposalRequest.govActionType = dbSyncData.type;
govActionProposalRequest.govMetadataUrl = dbSyncData.url;
govActionProposalRequest.status = dbSyncData.epoch_status;
govActionProposalRequest.endTime = dbSyncData.end_time;
govActionProposalRequest.txHash = Buffer.from(dbSyncData.hash).toString(
'hex',
);
Expand Down
1 change: 1 addition & 0 deletions worker-service/src/governance/mapper/vote.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class VoteMapper {
voteRequest.govActionType = dbSyncData.type;
voteRequest.govMetadataUrl = dbSyncData.gap_url;
voteRequest.status = dbSyncData.epoch_status;
voteRequest.endTime = dbSyncData.end_time;
voteRequest.txHash = dbSyncData.hash;
voteRequest.govActionProposalSubmitTime = dbSyncData.gap_submit_time;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('GovActionProposalService', () => {
govActionType: 'InfoAction',
govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json',
status: 'DROPPED',
endTime: new Date('2024-05-22T22:29:33.000Z'),
txHash:
'69aa81f4aa0140e8d2ab2b6642c403611cd730fab42e6c9f9e3e15d6d90bd3e9',
submitTime: new Date('2024-05-17T10:56:00.000Z'),
Expand All @@ -31,6 +32,7 @@ describe('GovActionProposalService', () => {
govMetadataUrl:
'https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt',
status: 'DROPPED',
endTime: new Date('2024-05-22T22:29:33.000Z'),
txHash:
'edef927af962664ed7a02bedfa913c7f1cd271494871c25ee7de66e941d83c79',
submitTime: new Date('2024-05-17T14:15:34.000Z'),
Expand All @@ -41,6 +43,7 @@ describe('GovActionProposalService', () => {
govActionType: 'InfoAction',
govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info',
status: 'DROPPED',
endTime: new Date('2024-05-23T22:27:46.000Z'),
txHash:
'b9532421430f6611c0170993e88dfa29b6aa0d4cce024ad88346c59be2b65b41',
submitTime: new Date('2024-05-18T12:29:22.000Z'),
Expand All @@ -51,6 +54,7 @@ describe('GovActionProposalService', () => {
govActionType: 'ParameterChange',
govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json',
status: 'DROPPED',
endTime: new Date('2024-05-23T22:27:46.000Z'),
txHash:
'6a3319f5ac57551c4cabf77d0603bd6c72f44e9d10830363d87eb34cb43afcb2',
submitTime: new Date('2024-05-18T18:25:26.000Z'),
Expand All @@ -61,6 +65,7 @@ describe('GovActionProposalService', () => {
govActionType: 'InfoAction',
govMetadataUrl: 'https://bit.ly/3zCH2HL',
status: 'DROPPED',
endTime: new Date('2024-05-25T22:29:48.000Z'),
txHash:
'cef93aface365b575e1f33987fad4093e2a8a06d31c01a260e0e7db325fc0b50',
submitTime: new Date('2024-05-20T04:39:16.000Z'),
Expand All @@ -72,6 +77,7 @@ describe('GovActionProposalService', () => {
govMetadataUrl:
'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
status: 'DROPPED',
endTime: new Date('2024-05-26T22:29:45.000Z'),
txHash:
'd775fbcb6006524abbffe6daf538e71941745b44a3a735852fbbd49fd7d59a95',
submitTime: new Date('2024-05-21T13:18:06.000Z'),
Expand All @@ -83,6 +89,7 @@ describe('GovActionProposalService', () => {
govMetadataUrl:
'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
status: 'DROPPED',
endTime: new Date('2024-05-26T22:29:45.000Z'),
txHash:
'db4dbeb5946e5d49778f457d9c5a460488c40af0b93d8b98111f5be11bf165a6',
submitTime: new Date('2024-05-21T15:08:38.000Z'),
Expand All @@ -94,6 +101,7 @@ describe('GovActionProposalService', () => {
govMetadataUrl:
'1111111111111111111111111111111111111111111111111111111111111111',
status: 'DROPPED',
endTime: new Date('2024-05-27T22:29:38.000Z'),
txHash:
'67820c121787464a9b670cf4c648f67cabd9573eb71b220214971ce467d25027',
submitTime: new Date('2024-05-22T08:08:20.000Z'),
Expand All @@ -104,6 +112,7 @@ describe('GovActionProposalService', () => {
govActionType: 'InfoAction',
govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info',
status: 'DROPPED',
endTime: new Date('2024-05-27T22:29:38.000Z'),
txHash:
'75d1c676f459f1192c7fd2c73423635a074c5e7b46497e00f44428861f460153',
submitTime: new Date('2024-05-22T10:24:59.000Z'),
Expand All @@ -115,6 +124,7 @@ describe('GovActionProposalService', () => {
govMetadataUrl:
'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
status: 'DROPPED',
endTime: new Date('2024-05-27T22:29:38.000Z'),
txHash:
'9bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397',
submitTime: new Date('2024-05-22T17:47:27.000Z'),
Expand Down Expand Up @@ -286,7 +296,7 @@ describe('GovActionProposalService', () => {
{
id: '1',
type: 'InfoAction',
end_time: '2024-05-22T22:29:33.000Z',
end_time: new Date('2024-05-22T22:29:33.000Z'),
voting_anchor_id: '1',
url: 'https://my-ip.at/test/cip-0100.common.json',
hash: new Uint8Array([
Expand All @@ -300,7 +310,7 @@ describe('GovActionProposalService', () => {
{
id: '2',
type: 'HardForkInitiation',
end_time: '2024-05-22T22:29:33.000Z',
end_time: new Date('2024-05-22T22:29:33.000Z'),
voting_anchor_id: '2',
url: 'https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt',
hash: new Uint8Array([
Expand All @@ -314,7 +324,7 @@ describe('GovActionProposalService', () => {
{
id: '3',
type: 'InfoAction',
end_time: '2024-05-23T22:27:46.000Z',
end_time: new Date('2024-05-23T22:27:46.000Z'),
voting_anchor_id: '4',
url: 'https://metadata.cardanoapi.io/data/Info',
hash: new Uint8Array([
Expand All @@ -327,7 +337,7 @@ describe('GovActionProposalService', () => {
{
id: '4',
type: 'ParameterChange',
end_time: '2024-05-23T22:27:46.000Z',
end_time: new Date('2024-05-23T22:27:46.000Z'),
voting_anchor_id: '1',
url: 'https://my-ip.at/test/cip-0100.common.json',
hash: new Uint8Array([
Expand All @@ -340,7 +350,7 @@ describe('GovActionProposalService', () => {
{
id: '5',
type: 'InfoAction',
end_time: '2024-05-25T22:29:48.000Z',
end_time: new Date('2024-05-25T22:29:48.000Z'),
voting_anchor_id: '62',
url: 'https://bit.ly/3zCH2HL',
hash: new Uint8Array([
Expand All @@ -353,7 +363,7 @@ describe('GovActionProposalService', () => {
{
id: '6',
type: 'InfoAction',
end_time: '2024-05-26T22:29:45.000Z',
end_time: new Date('2024-05-26T22:29:45.000Z'),
voting_anchor_id: '168',
url: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
hash: new Uint8Array([
Expand All @@ -367,7 +377,7 @@ describe('GovActionProposalService', () => {
{
id: '7',
type: 'InfoAction',
end_time: '2024-05-26T22:29:45.000Z',
end_time: new Date('2024-05-26T22:29:45.000Z'),
voting_anchor_id: '168',
url: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
hash: new Uint8Array([
Expand All @@ -381,7 +391,7 @@ describe('GovActionProposalService', () => {
{
id: '8',
type: 'HardForkInitiation',
end_time: '2024-05-27T22:29:38.000Z',
end_time: new Date('2024-05-27T22:29:38.000Z'),
voting_anchor_id: '216',
url: '1111111111111111111111111111111111111111111111111111111111111111',
hash: new Uint8Array([
Expand All @@ -394,7 +404,7 @@ describe('GovActionProposalService', () => {
{
id: '9',
type: 'InfoAction',
end_time: '2024-05-27T22:29:38.000Z',
end_time: new Date('2024-05-27T22:29:38.000Z'),
voting_anchor_id: '239',
url: 'https://metadata.cardanoapi.io/data/Info',
hash: new Uint8Array([
Expand All @@ -407,7 +417,7 @@ describe('GovActionProposalService', () => {
{
id: '10',
type: 'InfoAction',
end_time: '2024-05-27T22:29:38.000Z',
end_time: new Date('2024-05-27T22:29:38.000Z'),
voting_anchor_id: '168',
url: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld',
hash: new Uint8Array([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export class GovActionProposalService extends CommonService {
request.govMetadataUrl,
);
const axiosData = await this.getGovActionProposalFromUrl(govMetadataUrl);
const endTime = await this.getEndTime(
request.submitTime,
endTimeInterval,
);
let endTime: Date = request.endTime;
if (!request.endTime) {
endTime = await this.getEndTime(request.submitTime, endTimeInterval);
}
const govActionProposal: Partial<GovActionProposalDto> = {
id: request.id,
votingAnchorId: request.votingAnchorId,
Expand Down
3 changes: 3 additions & 0 deletions worker-service/src/governance/services/vote.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ describe('VoteService', () => {
govActionType: 'InfoAction',
govMetadataUrl: 'https://gap-url-1.jsonld',
status: 'ACTIVE',
endTime: null,
txHash:
'970e331a2e340597636b26bc8ab44c386cd687d57d86698b81ecce9d43010c0c',
},
Expand All @@ -221,6 +222,7 @@ describe('VoteService', () => {
govActionType: 'InfoAction',
govMetadataUrl: 'https://gap-url-2.jsonld',
status: 'ACTIVE',
endTime: null,
txHash:
'0c0e331a2e340597636b26bc8ab44c386cd687d57d86698b81ecce9d43010c97',
},
Expand All @@ -237,6 +239,7 @@ describe('VoteService', () => {
govActionType: 'InfoAction',
govMetadataUrl: 'https://gap-url-3.jsonld',
status: 'ACTIVE',
endTime: null,
txHash:
'630c0e331a2e3405976b26bc8ab44c386cd687d57d86698b81ecce9d43010c97',
},
Expand Down
11 changes: 7 additions & 4 deletions worker-service/src/governance/services/vote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ export class VoteService extends CommonService {
const endTimeInterval: number =
this.configService.getOrThrow('EPOCH_DURATION') *
this.configService.getOrThrow('GAP_DURATION_IN_EPOCH_COUNT');
const endTime = await this.getEndTime(
voteRequest.govActionProposalSubmitTime,
endTimeInterval,
);
let endTime: Date = voteRequest.endTime;
if (!voteRequest.endTime) {
endTime = await this.getEndTime(
voteRequest.govActionProposalSubmitTime,
endTimeInterval,
);
}
const govMetadataUrl = await this.transformIpfsUrl(
voteRequest.govMetadataUrl,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
select
gap.id, -- Should be id value from Governance Action Proposal table
gap.type, -- Should be Governance Action Proposal category (ParameterChange, HardForkInitiation, TreasuryWithdrawals...)
gap_exp_epoch.end_time, -- Should be GAP "Expiry date" info when clicking on show more button
gap.voting_anchor_id, -- Should be anchor id for URL that contins JSon governance action metadata
va.url, -- Should be a URL that contains JSon governance action metadata
gap_tx.hash, -- Should be transaction hash from tx table
gap_block.time, -- Should be Governance Action Proposal "Submit time"
case
when gap.ratified_epoch is not null then 'RATIFIED'
when gap.enacted_epoch is not null then 'ENACTED'
when gap.ratified_epoch is not null then 'RATIFIED'
when gap.dropped_epoch is not null then 'DROPPED'
when gap.expired_epoch is not null then 'EXPIRED'
else 'ACTIVE'
end as epoch_status
from gov_action_proposal gap
left join tx gap_tx on gap_tx.id = gap.tx_id
left join epoch gap_exp_epoch on gap_exp_epoch.id = gap.expiration
left join voting_anchor va on va.id = gap.voting_anchor_id
left join block gap_block on gap_block.id = gap_tx.block_id
limit :limit offset :offset;
Loading

0 comments on commit 6dd66d0

Please sign in to comment.