From e077b9b0615617014db3ffffff19a2e642099977 Mon Sep 17 00:00:00 2001 From: ppe Date: Fri, 3 Mar 2023 12:39:54 +0100 Subject: [PATCH] v1.2.55 --- package.json | 6 +- .../integration/basic/pst-auto-sync.test.ts | 59 ++++++++++--------- .../basic/pst-kv-auto-sync.test.ts | 56 +++++++++--------- src/__tests__/regression/read-state.test.ts | 2 +- src/__tests__/unit/evaluation-options.test.ts | 7 ++- 5 files changed, 68 insertions(+), 62 deletions(-) diff --git a/package.json b/package.json index 33ba0549..c0382c98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "warp-contracts", - "version": "1.2.54", + "version": "1.2.55", "description": "An implementation of the SmartWeave smart contract protocol.", "types": "./lib/types/index.d.ts", "main": "./lib/cjs/index.js", @@ -102,8 +102,8 @@ "ts-jest": "^28.0.7", "ts-node": "^10.2.1", "typescript": "^4.9.5", - "ws": "^8.11.0", - "warp-contracts-plugin-deploy": "1.0.0-beta.16" + "warp-contracts-plugin-deploy": "1.0.0-beta.16", + "ws": "^8.11.0" }, "resolutions": { "bn.js": "5.2.1", diff --git a/src/__tests__/integration/basic/pst-auto-sync.test.ts b/src/__tests__/integration/basic/pst-auto-sync.test.ts index 423bdbdc..7b438dd0 100644 --- a/src/__tests__/integration/basic/pst-auto-sync.test.ts +++ b/src/__tests__/integration/basic/pst-auto-sync.test.ts @@ -9,7 +9,7 @@ import { PstState, PstContract } from '../../../contract/PstContract'; import { Warp } from '../../../core/Warp'; import { WarpFactory } from '../../../core/WarpFactory'; import { LoggerFactory } from '../../../logging/LoggerFactory'; -import { DeployPlugin } from "warp-contracts-plugin-deploy"; +import { DeployPlugin } from 'warp-contracts-plugin-deploy'; // note: each tests suit (i.e. file with tests that Jest is running concurrently // with another files has to have ArLocal set to a different port!) @@ -29,38 +29,38 @@ describe('Testing the Profit Sharing Token', () => { let contractTxId: string; let pst: PstContract; - const actualFetch = global.fetch + const actualFetch = global.fetch; let responseData = { - sortKey: "", + sortKey: '', state: {} - } - let firstSortKey = '' + }; + let firstSortKey = ''; const remoteCalls = { total: 0, - measure: function() { + measure: function () { const self = this; const start = self.total; return { diff: () => self.total - start - } + }; } - } + }; - const localWarp = async function() { + const localWarp = async function () { if (!arlocal) { arlocal = new ArLocal(AR_PORT, false); await arlocal.start(); } return WarpFactory.forLocal(AR_PORT).use(new DeployPlugin()); - } + }; - const autoSyncPst = async function() { + const autoSyncPst = async function () { const autoSyncPst = (await localWarp()).pst(contractTxId); autoSyncPst.setEvaluationOptions({ remoteStateSyncEnabled: true - }) + }); return autoSyncPst; - } + }; beforeAll(async () => { LoggerFactory.INST.logLevel('error'); @@ -98,15 +98,17 @@ describe('Testing the Profit Sharing Token', () => { await mineBlock(warp); - jest - .spyOn(global, 'fetch') - .mockImplementation( async (input: string, init) => { - if (input.includes(pst.evaluationOptions().remoteStateSyncSource)) { - remoteCalls.total++; - return Promise.resolve({ json: () => Promise.resolve(responseData), ok: true, status: 200 }) as Promise; - } - return actualFetch(input, init); - }) + jest.spyOn(global, 'fetch').mockImplementation(async (input: string, init) => { + if (input.includes(pst.evaluationOptions().remoteStateSyncSource)) { + remoteCalls.total++; + return Promise.resolve({ + json: () => Promise.resolve(responseData), + ok: true, + status: 200 + }) as Promise; + } + return actualFetch(input, init); + }); }); afterAll(async () => { @@ -164,15 +166,18 @@ describe('Testing the Profit Sharing Token', () => { expect((await pst.currentState()).balances['uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M']).toEqual(10000000 + 550); const syncPst = await autoSyncPst(); - expect((await syncPst.currentState()).balances['uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M']).toEqual(10000000 + 100); + expect((await syncPst.currentState()).balances['uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M']).toEqual( + 10000000 + 100 + ); expect((await syncPst.currentState()).balances[walletAddress]).toEqual(555669 - 100); syncPst.setEvaluationOptions({ remoteStateSyncEnabled: false - }) + }); expect((await syncPst.currentState()).balances[walletAddress]).toEqual(555669 - 550); expect((await syncPst.currentState()).balances['uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M']).toEqual( - 10000000 + 550); + 10000000 + 550 + ); expect(dreCalls.diff()).toEqual(2); }); @@ -186,12 +191,10 @@ describe('Testing the Profit Sharing Token', () => { expect(state.cachedValue.state).toEqual(initialState); const syncPst = await autoSyncPst(); - - const syncState = (await syncPst.readState(firstSortKey)); + const syncState = await syncPst.readState(firstSortKey); expect(await syncState.cachedValue.state).toEqual(initialState); expect(syncState.cachedValue.state.balances['uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M']).toEqual(10000000); expect(syncState.cachedValue.state.balances['33F0QHcb22W7LwWR1iRC8Az1ntZG09XQ03YWuw2ABqA']).toEqual(23111222); expect(dreCalls.diff()).toEqual(1); }); - }); diff --git a/src/__tests__/integration/basic/pst-kv-auto-sync.test.ts b/src/__tests__/integration/basic/pst-kv-auto-sync.test.ts index 31519800..570272e6 100644 --- a/src/__tests__/integration/basic/pst-kv-auto-sync.test.ts +++ b/src/__tests__/integration/basic/pst-kv-auto-sync.test.ts @@ -7,15 +7,14 @@ import path from 'path'; import { mineBlock } from '../_helpers'; import { PstState, PstContract } from '../../../contract/PstContract'; import { Warp } from '../../../core/Warp'; -import { DEFAULT_LEVEL_DB_LOCATION, defaultCacheOptions, WarpFactory } from "../../../core/WarpFactory"; +import { DEFAULT_LEVEL_DB_LOCATION, defaultCacheOptions, WarpFactory } from '../../../core/WarpFactory'; import { LoggerFactory } from '../../../logging/LoggerFactory'; -import { DeployPlugin } from "warp-contracts-plugin-deploy"; +import { DeployPlugin } from 'warp-contracts-plugin-deploy'; // note: each tests suit (i.e. file with tests that Jest is running concurrently // with another files has to have ArLocal set to a different port!) const AR_PORT = 1826; - describe('Testing the Profit Sharing Token', () => { let contractSrc: string; @@ -30,23 +29,23 @@ describe('Testing the Profit Sharing Token', () => { let contractTxId: string; let pst: PstContract; - const actualFetch = global.fetch + const actualFetch = global.fetch; let responseData = { - sortKey: "", + sortKey: '', state: {} - } + }; const remoteCalls = { total: 0, - measure: function() { + measure: function () { const self = this; const start = self.total; return { diff: () => self.total - start - } + }; } - } + }; - const localWarp = async function() { + const localWarp = async function () { if (!arlocal) { arlocal = new ArLocal(AR_PORT, false); await arlocal.start(); @@ -55,20 +54,20 @@ describe('Testing the Profit Sharing Token', () => { host: 'localhost', port: AR_PORT, protocol: 'http' - }) + }); } return WarpFactory.forLocal(AR_PORT, arweave, { ...defaultCacheOptions, inMemory: true }).use(new DeployPlugin()); - } + }; - const autoSyncPst = async function() { + const autoSyncPst = async function () { // const autoSyncPst = warp.pst(contractTxId); const autoSyncPst = (await localWarp()).pst(contractTxId); autoSyncPst.setEvaluationOptions({ remoteStateSyncEnabled: true - }) + }); return autoSyncPst; - } + }; beforeAll(async () => { LoggerFactory.INST.logLevel('error'); @@ -93,7 +92,7 @@ describe('Testing the Profit Sharing Token', () => { src: contractSrc, evaluationManifest: { evaluationOptions: { - useKVStorage: true, + useKVStorage: true } } })); @@ -103,15 +102,17 @@ describe('Testing the Profit Sharing Token', () => { await mineBlock(warp); - jest - .spyOn(global, 'fetch') - .mockImplementation( async (input: string, init) => { - if (input.includes(pst.evaluationOptions().remoteStateSyncSource)) { - remoteCalls.total++; - return Promise.resolve({ json: () => Promise.resolve(responseData), ok: true, status: 200 }) as Promise; - } - return actualFetch(input, init); - }) + jest.spyOn(global, 'fetch').mockImplementation(async (input: string, init) => { + if (input.includes(pst.evaluationOptions().remoteStateSyncSource)) { + remoteCalls.total++; + return Promise.resolve({ + json: () => Promise.resolve(responseData), + ok: true, + status: 200 + }) as Promise; + } + return actualFetch(input, init); + }); }); afterAll(async () => { @@ -199,7 +200,9 @@ describe('Testing the Profit Sharing Token', () => { expect(await syncPst.currentState()).toEqual(initialState); expect((await syncPst.currentBalance(walletAddress)).balance).toEqual(555669 - 500); - expect((await syncPst.currentBalance('uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M')).balance).toEqual(10000000 + 500); + expect((await syncPst.currentBalance('uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M')).balance).toEqual( + 10000000 + 500 + ); expect((await syncPst.getStorageValues([walletAddress])).cachedValue.get(walletAddress)).toEqual(555669 - 500); expect( @@ -215,5 +218,4 @@ describe('Testing the Profit Sharing Token', () => { expect((await syncPst.getStorageValues(['foo'])).cachedValue.get('foo')).toBeNull(); expect(dreCalls.diff()).toEqual(0); }); - }); diff --git a/src/__tests__/regression/read-state.test.ts b/src/__tests__/regression/read-state.test.ts index 09e6bab2..26347c8e 100644 --- a/src/__tests__/regression/read-state.test.ts +++ b/src/__tests__/regression/read-state.test.ts @@ -70,7 +70,7 @@ describe.each(chunked)('v1 compare.suite %#', (contracts: string[]) => { } ) .build() - .use(new DeployPlugin()) + .use(new DeployPlugin()); const result2 = await warp .use(new DeployPlugin()) diff --git a/src/__tests__/unit/evaluation-options.test.ts b/src/__tests__/unit/evaluation-options.test.ts index c9e9bd2a..ea2d7477 100644 --- a/src/__tests__/unit/evaluation-options.test.ts +++ b/src/__tests__/unit/evaluation-options.test.ts @@ -18,7 +18,7 @@ describe('Evaluation options evaluator', () => { maxInteractionEvaluationTimeSeconds: 60, mineArLocalBlocks: true, remoteStateSyncEnabled: false, - remoteStateSyncSource: "https://dre-1.warp.cc/contract", + remoteStateSyncSource: 'https://dre-1.warp.cc/contract', sequencerUrl: 'https://d1o5nlqr4okus2.cloudfront.net/', sourceType: SourceType.BOTH, stackTrace: { @@ -57,7 +57,7 @@ describe('Evaluation options evaluator', () => { maxInteractionEvaluationTimeSeconds: 60, mineArLocalBlocks: true, remoteStateSyncEnabled: false, - remoteStateSyncSource: "https://dre-1.warp.cc/contract", + remoteStateSyncSource: 'https://dre-1.warp.cc/contract', sequencerUrl: 'https://d1o5nlqr4okus2.cloudfront.net/', sourceType: SourceType.BOTH, stackTrace: { @@ -90,7 +90,8 @@ describe('Evaluation options evaluator', () => { maxInteractionEvaluationTimeSeconds: 60, mineArLocalBlocks: true, remoteStateSyncEnabled: false, - remoteStateSyncSource: "https://dre-1.warp.cc/contract", sequencerUrl: 'https://d1o5nlqr4okus2.cloudfront.net/', + remoteStateSyncSource: 'https://dre-1.warp.cc/contract', + sequencerUrl: 'https://d1o5nlqr4okus2.cloudfront.net/', sourceType: 'both', stackTrace: { saveState: false