Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
add getExpiration to SpellService
Browse files Browse the repository at this point in the history
  • Loading branch information
b-pmcg committed Oct 14, 2021
1 parent a41e09c commit f28b556
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/dai-plugin-governance/src/SpellService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class SpellService extends PublicService {
this.executionDate = {};
this.scheduledDate = {};
this.nextCastTime = {};
this.expiration = {};
this.executiveHash = {};
this.officeHours = {};
}
Expand Down Expand Up @@ -50,6 +51,18 @@ export default class SpellService extends PublicService {
return this.nextCastTime[spellAddress];
}

async getExpiration(spellAddress) {
if (this.expiration[spellAddress]) return this.expiration[spellAddress];
const spell = this.get('smartContract').getContractByAddressAndAbi(
spellAddress,
DsSpellAbi
);
const expiration = await spell.expiration();
if (!expiration.toNumber()) return undefined;
this.expiration[spellAddress] = new Date(expiration.toNumber() * 1000);
return this.expiration[spellAddress];
}

async getScheduledDate(spellAddress) {
if (this.scheduledDate[spellAddress])
return this.scheduledDate[spellAddress];
Expand Down
9 changes: 9 additions & 0 deletions packages/dai-plugin-governance/test/SpellService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe('use mainnet', () => {
expect(eta).toEqual(new Date('2020-01-26T11:53:19.000Z'));
});

test('get spell expiration', async () => {
const eta = await spellService.getExpiration(
'0x9400d4D59134af2a48a4bf4237E809A80f90Fe63'
);
expect(eta).toEqual(new Date('2021-11-07T20:22:48.000Z'));
});

//TODO: add test for getNextCastTime();

test('get executive hash text', async () => {
const done = await spellService.getExecutiveHash(
'0x9400d4D59134af2a48a4bf4237E809A80f90Fe63'
Expand Down

0 comments on commit f28b556

Please sign in to comment.