diff --git a/src/__tests__/integration/data/wasm/counter.wasm b/src/__tests__/integration/data/wasm/counter.wasm index 6d5c480..17437af 100644 Binary files a/src/__tests__/integration/data/wasm/counter.wasm and b/src/__tests__/integration/data/wasm/counter.wasm differ diff --git a/src/__tests__/integration/inf-loop.test.ts b/src/__tests__/integration/inf-loop.test.ts index a294d0c..d402204 100644 --- a/src/__tests__/integration/inf-loop.test.ts +++ b/src/__tests__/integration/inf-loop.test.ts @@ -15,6 +15,7 @@ let contract: Contract; interface ExampleContractState { counter: number; } + describe('Testing the SmartWeave client', () => { let contractSrc: string; diff --git a/src/__tests__/integration/wasm-deploy-write-read.test.ts b/src/__tests__/integration/wasm-deploy-write-read.test.ts index a5c13be..34fff6e 100644 --- a/src/__tests__/integration/wasm-deploy-write-read.test.ts +++ b/src/__tests__/integration/wasm-deploy-write-read.test.ts @@ -9,6 +9,8 @@ import { addFunds, mineBlock } from './_helpers'; interface ExampleContractState { counter: number; + firstName: string; + lastName: string; } describe('Testing the SmartWeave client for WASM contract', () => { @@ -36,8 +38,6 @@ describe('Testing the SmartWeave client for WASM contract', () => { }); LoggerFactory.INST.logLevel('error'); - LoggerFactory.INST.logLevel('debug', 'WasmContractHandlerApi'); - LoggerFactory.INST.logLevel('debug', 'WASM'); smartweave = SmartWeaveNodeFactory.memCached(arweave); @@ -79,7 +79,10 @@ describe('Testing the SmartWeave client for WASM contract', () => { }); it('should properly read initial state', async () => { - expect((await contract.readState()).state.counter).toEqual(0); + const contractState = (await contract.readState()).state; + expect(contractState.counter).toEqual(0); + expect(contractState.firstName).toEqual("first_ppe"); + expect(contractState.lastName).toEqual("last_ppe"); }); it('should properly register interactions', async () => { @@ -105,7 +108,7 @@ describe('Testing the SmartWeave client for WASM contract', () => { function: 'increment' }); - expect(result.gasUsed).toEqual(9079017); + expect(result.gasUsed).toEqual(9053274); }); it('should return stable gas results', async () => { @@ -120,7 +123,7 @@ describe('Testing the SmartWeave client for WASM contract', () => { } results.forEach((result) => { - expect(result.gasUsed).toEqual(9079017); + expect(result.gasUsed).toEqual(9053274); }); }); diff --git a/src/core/modules/impl/CacheableStateEvaluator.ts b/src/core/modules/impl/CacheableStateEvaluator.ts index c0fe879..2d83f38 100644 --- a/src/core/modules/impl/CacheableStateEvaluator.ts +++ b/src/core/modules/impl/CacheableStateEvaluator.ts @@ -40,6 +40,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { const cachedState = executionContext.cachedState; if (cachedState?.cachedHeight === requestedBlockHeight) { + executionContext.handler?.initState(cachedState.cachedValue.state); return cachedState.cachedValue; } @@ -93,6 +94,7 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator { // if cache is up-to date - return immediately to speed-up the whole process if (missingInteractions.length === 0 && cachedState) { this.cLogger.debug(`State up to requested height [${requestedBlockHeight}] fully cached!`); + executionContext.handler?.initState(cachedState.cachedValue.state); return cachedState.cachedValue; } } diff --git a/src/core/modules/impl/DefaultCreateContract.ts b/src/core/modules/impl/DefaultCreateContract.ts index feb8bd3..42877a9 100644 --- a/src/core/modules/impl/DefaultCreateContract.ts +++ b/src/core/modules/impl/DefaultCreateContract.ts @@ -45,7 +45,7 @@ export class DefaultCreateContract implements CreateContract { throw new Error(`No info about source type in wasm binary. Did you forget to export global "type" value?`); } // @ts-ignore - const type = module.instance.exports.type.value; + const type = module.instance.exports.type(); if (!wasmTypeMapping.has(type)) { throw new Error(`Unknown wasm source type ${type}`); } diff --git a/src/core/modules/impl/DefaultStateEvaluator.ts b/src/core/modules/impl/DefaultStateEvaluator.ts index e994df3..409f02a 100644 --- a/src/core/modules/impl/DefaultStateEvaluator.ts +++ b/src/core/modules/impl/DefaultStateEvaluator.ts @@ -61,7 +61,7 @@ export abstract class DefaultStateEvaluator implements StateEvaluator { let currentState = baseState.state; const validity = baseState.validity; - executionContext.handler.initState(currentState); + executionContext?.handler.initState(currentState); this.logger.info( `Evaluating state for ${contractDefinition.txId} [${missingInteractions.length} non-cached of ${sortedInteractions.length} all]` diff --git a/tools/data/wasm/counter.wasm b/tools/data/wasm/counter.wasm deleted file mode 100644 index 6d5c480..0000000 Binary files a/tools/data/wasm/counter.wasm and /dev/null differ diff --git a/tools/data/wasm/optimized.wasm b/tools/data/wasm/optimized.wasm new file mode 100644 index 0000000..8a29395 Binary files /dev/null and b/tools/data/wasm/optimized.wasm differ