From f28b556d9021f9387f2b3fb5f1dc67f32383a854 Mon Sep 17 00:00:00 2001 From: Phil Bain Date: Thu, 14 Oct 2021 13:03:26 -0600 Subject: [PATCH] add getExpiration to SpellService --- packages/dai-plugin-governance/src/SpellService.js | 13 +++++++++++++ .../dai-plugin-governance/test/SpellService.test.js | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/dai-plugin-governance/src/SpellService.js b/packages/dai-plugin-governance/src/SpellService.js index e961da45d..91dfa023c 100644 --- a/packages/dai-plugin-governance/src/SpellService.js +++ b/packages/dai-plugin-governance/src/SpellService.js @@ -16,6 +16,7 @@ export default class SpellService extends PublicService { this.executionDate = {}; this.scheduledDate = {}; this.nextCastTime = {}; + this.expiration = {}; this.executiveHash = {}; this.officeHours = {}; } @@ -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]; diff --git a/packages/dai-plugin-governance/test/SpellService.test.js b/packages/dai-plugin-governance/test/SpellService.test.js index 656921a3a..dc6837ae0 100644 --- a/packages/dai-plugin-governance/test/SpellService.test.js +++ b/packages/dai-plugin-governance/test/SpellService.test.js @@ -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'