From d7999fe1c8575bb1dd095b68952c9946b77d64e0 Mon Sep 17 00:00:00 2001 From: Asia Date: Mon, 4 Nov 2024 13:38:58 +0100 Subject: [PATCH] v1.4.45-warpy.1 --- package.json | 2 +- src/__tests__/integration/basic/pst.test.ts | 42 ++++++++----------- src/contract/HandlerBasedContract.ts | 2 +- src/core/modules/StateEvaluator.ts | 2 +- .../modules/impl/CacheableStateEvaluator.ts | 8 ++-- .../impl/handler/AbstractContractHandler.ts | 3 +- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 5d96f0d9..1400083e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "warp-contracts", - "version": "1.4.45-warpy.0", + "version": "1.4.45-warpy.1", "description": "An implementation of the SmartWeave smart contract protocol.", "types": "./lib/types/index.d.ts", "main": "./lib/cjs/index.js", diff --git a/src/__tests__/integration/basic/pst.test.ts b/src/__tests__/integration/basic/pst.test.ts index 47a3f41d..14d53534 100644 --- a/src/__tests__/integration/basic/pst.test.ts +++ b/src/__tests__/integration/basic/pst.test.ts @@ -135,36 +135,28 @@ describe('Testing the Profit Sharing Token', () => { }); it('should properly dispatch an event', async () => { - let handlerCalled = false; const interactionResult = await pst.writeInteraction({ function: 'dispatchEvent' }); await mineBlock(warp); - warp.eventTarget.addEventListener('interactionCompleted', interactionCompleteHandler); - await pst.readState(); - - expect(handlerCalled).toBeTruthy(); - - function interactionCompleteHandler(event: CustomEvent) { - expect(event.type).toEqual('interactionCompleted'); - expect(event.detail.contractTxId).toEqual(pst.txId()); - expect(event.detail.caller).toEqual(walletAddress); - expect(event.detail.transactionId).toEqual(interactionResult.originalTxId); - expect(event.detail.sortKey).not.toBeNull(); - expect(event.detail.input).not.toBeNull(); - expect(event.detail.blockHeight).toBeGreaterThan(0); - expect(event.detail.blockTimestamp).toBeGreaterThan(0); - expect(event.detail.data).toEqual({ - value1: 'foo', - value2: 'bar' - }); - expect(event.detail.input).toEqual({ - function: 'dispatchEvent' - }); - handlerCalled = true; - warp.eventTarget.removeEventListener('interactionCompleted', interactionCompleteHandler); - } + const { cachedValue } = await pst.readState(); + const event = cachedValue.events[0]; + + expect(event.contractTxId).toEqual(pst.txId()); + expect(event.caller).toEqual(walletAddress); + expect(event.transactionId).toEqual(interactionResult.originalTxId); + expect(event.sortKey).not.toBeNull(); + expect(event.input).not.toBeNull(); + expect(event.blockHeight).toBeGreaterThan(0); + expect(event.blockTimestamp).toBeGreaterThan(0); + expect(event.data).toEqual({ + value1: 'foo', + value2: 'bar' + }); + expect(event.input).toEqual({ + function: 'dispatchEvent' + }); }); it("should properly evolve contract's source code", async () => { diff --git a/src/contract/HandlerBasedContract.ts b/src/contract/HandlerBasedContract.ts index 5d3d7951..9a50af6e 100644 --- a/src/contract/HandlerBasedContract.ts +++ b/src/contract/HandlerBasedContract.ts @@ -1154,7 +1154,7 @@ export class HandlerBasedContract implements Contract { ): SortKeyCacheResult> { const dreCachedState = new SortKeyCacheResult( result.sortKey, - new EvalStateResult(result.state, {}, result.errorMessages) + new EvalStateResult(result.state, {}, result.errorMessages, []) ); this.getRoot()._dreStates.set(contractTxId, dreCachedState); return dreCachedState; diff --git a/src/core/modules/StateEvaluator.ts b/src/core/modules/StateEvaluator.ts index 603dbe78..5ba373ca 100644 --- a/src/core/modules/StateEvaluator.ts +++ b/src/core/modules/StateEvaluator.ts @@ -98,7 +98,7 @@ export class EvalStateResult { readonly state: State, readonly validity: Record, readonly errorMessages: Record, - readonly events?: InteractionCompleteEvent[] + readonly events: InteractionCompleteEvent[] ) {} } diff --git a/src/core/modules/impl/CacheableStateEvaluator.ts b/src/core/modules/impl/CacheableStateEvaluator.ts index 17a15db7..55b64712 100644 --- a/src/core/modules/impl/CacheableStateEvaluator.ts +++ b/src/core/modules/impl/CacheableStateEvaluator.ts @@ -68,7 +68,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { if (isFirstEvaluation) { executionContext.handler?.initState(baseState); this.cLogger.debug('Inserting initial state into cache'); - const stateToCache = new EvalStateResult(baseState, {}, {}); + const stateToCache = new EvalStateResult(baseState, {}, {}, []); // no real sort-key - as we're returning the initial state await this.cache.put(new CacheKey(contractTxId, genesisSortKey), stateToCache); @@ -81,7 +81,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { // eval state for the missing transactions - starting from the latest value from cache. return await this.doReadState( missingInteractions, - new EvalStateResult(baseState, baseValidity, baseErrorMessages), + new EvalStateResult(baseState, baseValidity, baseErrorMessages, []), executionContext ); } @@ -182,7 +182,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { if (transaction.confirmationStatus !== undefined && transaction.confirmationStatus !== 'confirmed') { return; } - const stateToCache = new EvalStateResult(state.state, state.validity || {}, state.errorMessages || {}); + const stateToCache = new EvalStateResult(state.state, state.validity || {}, state.errorMessages || {}, []); this.cLogger.debug('Putting into cache', { contractTxId, @@ -200,7 +200,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { state: State, validity: Record ): Promise>> { - const stateToCache = new EvalStateResult(state, validity, {}); + const stateToCache = new EvalStateResult(state, validity, {}, []); await this.cache.put(new CacheKey(contractTxId, sortKey), stateToCache); return new SortKeyCacheResult(sortKey, stateToCache); } diff --git a/src/core/modules/impl/handler/AbstractContractHandler.ts b/src/core/modules/impl/handler/AbstractContractHandler.ts index 3aa5ca07..a3964098 100644 --- a/src/core/modules/impl/handler/AbstractContractHandler.ts +++ b/src/core/modules/impl/handler/AbstractContractHandler.ts @@ -101,7 +101,8 @@ export abstract class AbstractContractHandler implements HandlerApi