Skip to content

Commit

Permalink
v1.4.45-warpy.1
Browse files Browse the repository at this point in the history
  • Loading branch information
asiaziola committed Nov 4, 2024
1 parent 10a6cd7 commit d7999fe
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
42 changes: 17 additions & 25 deletions src/__tests__/integration/basic/pst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InteractionCompleteEvent>) {
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 () => {
Expand Down
2 changes: 1 addition & 1 deletion src/contract/HandlerBasedContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
): SortKeyCacheResult<EvalStateResult<State>> {
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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/modules/StateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class EvalStateResult<State> {
readonly state: State,
readonly validity: Record<string, boolean>,
readonly errorMessages: Record<string, string>,
readonly events?: InteractionCompleteEvent[]
readonly events: InteractionCompleteEvent[]
) {}
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/modules/impl/CacheableStateEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
);
}
Expand Down Expand Up @@ -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,
Expand All @@ -200,7 +200,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
state: State,
validity: Record<string, boolean>
): Promise<SortKeyCacheResult<EvalStateResult<State>>> {
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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/modules/impl/handler/AbstractContractHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export abstract class AbstractContractHandler<State> implements HandlerApi<State
...result.originalValidity,
[activeTx.id]: result.type == 'ok'
},
errorMessages: resultErrorMessages
errorMessages: resultErrorMessages,
events: []
},
activeTx.sortKey
);
Expand Down

0 comments on commit d7999fe

Please sign in to comment.