Skip to content

Commit

Permalink
v1.2.55
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Mar 3, 2023
1 parent 0bc1247 commit e077b9b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 62 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
59 changes: 31 additions & 28 deletions src/__tests__/integration/basic/pst-auto-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand All @@ -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');
Expand Down Expand Up @@ -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<Response>;
}
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<Response>;
}
return actualFetch(input, init);
});
});

afterAll(async () => {
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});

});
56 changes: 29 additions & 27 deletions src/__tests__/integration/basic/pst-kv-auto-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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');
Expand All @@ -93,7 +92,7 @@ describe('Testing the Profit Sharing Token', () => {
src: contractSrc,
evaluationManifest: {
evaluationOptions: {
useKVStorage: true,
useKVStorage: true
}
}
}));
Expand All @@ -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<Response>;
}
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<Response>;
}
return actualFetch(input, init);
});
});

afterAll(async () => {
Expand Down Expand Up @@ -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(
Expand All @@ -215,5 +218,4 @@ describe('Testing the Profit Sharing Token', () => {
expect((await syncPst.getStorageValues(['foo'])).cachedValue.get('foo')).toBeNull();
expect(dreCalls.diff()).toEqual(0);
});

});
2 changes: 1 addition & 1 deletion src/__tests__/regression/read-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 4 additions & 3 deletions src/__tests__/unit/evaluation-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e077b9b

Please sign in to comment.