diff --git a/src/keeper/Event.ts b/src/keeper/Event.ts index 2138e5b..f4c59ee 100644 --- a/src/keeper/Event.ts +++ b/src/keeper/Event.ts @@ -26,10 +26,12 @@ export default class Event { this.interval) } - public async listenOnce() { + public listenOnce(callback: any) { this.listen((events: any[]) => { - EventListener.unsubscribe(this) - return events + if (events) { + EventListener.unsubscribe(this) + callback(events[0]) + } }) } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index c954633..2cb7e98 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -124,7 +124,7 @@ export default class Ocean { const storedDdo = await aquarius.storeDDO(ddo) - Logger.log(JSON.stringify(storedDdo, null, 2)) + // Logger.log(JSON.stringify(storedDdo, null, 2)) await didRegistry.registerAttribute( assetId, diff --git a/test/keeper/Event.test.ts b/test/keeper/Event.test.ts index 4dc51a5..eadbe19 100644 --- a/test/keeper/Event.test.ts +++ b/test/keeper/Event.test.ts @@ -52,19 +52,25 @@ describe("EventListener", () => { describe("#listenOnce()", () => { - xit("should listen once", async () => { + it("should listen once", (done) => { const acc = accounts[1] + const countBefore = EventListener.count() const event = EventListener.subscribe("OceanToken", "Transfer", { to: acc.getId(), }) - const events = await event.listenOnce() + event.listenOnce( + (data: any) => { - assert(events, "no events") + assert(data) + assert(data.blockNumber) + assert(EventListener.count() === countBefore) + done() + }) const {market} = keeper