Skip to content

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Apr 14, 2023
1 parent cc47e63 commit a946381
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 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.3.5-beta.0",
"version": "1.4.0",
"description": "An implementation of the SmartWeave smart contract protocol.",
"types": "./lib/types/index.d.ts",
"main": "./lib/cjs/index.js",
Expand Down
36 changes: 24 additions & 12 deletions src/__tests__/integration/basic/pst-kv-check-iteration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Arweave from 'arweave';
import { JWKInterface } from 'arweave/node/lib/wallet';
import path from 'path';
import { mineBlock } from '../_helpers';
import { PstContract, PstState } from "../../../contract/PstContract";
import { PstContract, PstState } from '../../../contract/PstContract';
import { Warp } from '../../../core/Warp';
import { DEFAULT_LEVEL_DB_LOCATION, WarpFactory } from '../../../core/WarpFactory';
import { LoggerFactory } from '../../../logging/LoggerFactory';
Expand Down Expand Up @@ -189,24 +189,36 @@ describe('Testing the PST kv storage range access', () => {

expect((await pst.currentBalance(aliceWalletAddress)).balance).toEqual(200_000);
expect((await pst.currentBalance(walletAddress)).balance).toEqual(555669 - 655 - 200_000);
expect((await pst.getStorageValues(['check.' + walletAddress + '.' + aliceWalletAddress]))
.cachedValue.get('check.' + walletAddress + '.' + aliceWalletAddress))
.toBeNull();
expect(
(await pst.getStorageValues(['check.' + walletAddress + '.' + aliceWalletAddress])).cachedValue.get(
'check.' + walletAddress + '.' + aliceWalletAddress
)
).toBeNull();
});

it('should withdraw last check', async () => {
expect((await pst.viewState<unknown, ChecksWrittenResult>({ function: 'checksActive' })).result.total)
.toEqual(207_500);
expect((await pst.viewState<unknown, ChecksWrittenResult>({ function: 'checksActive' })).result.total).toEqual(
207_500
);

await pst.writeInteraction({ function: 'withdrawLastCheck', target: 'uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M' });
await pst.writeInteraction({ function: 'withdrawLastCheck', target: 'uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M' });
await pst.writeInteraction({ function: 'withdrawLastCheck', target: 'uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M' });
await pst.writeInteraction({
function: 'withdrawLastCheck',
target: 'uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M'
});
await pst.writeInteraction({
function: 'withdrawLastCheck',
target: 'uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M'
});
await pst.writeInteraction({
function: 'withdrawLastCheck',
target: 'uhE-QeYS8i4pmUtnxQyHD7dzXFNaJ9oMK-IM-QPNY6M'
});

await mineBlock(warp);

expect((await pst.viewState<unknown, ChecksWrittenResult>({ function: 'checksActive' })).result.total)
.toEqual(200_000);

expect((await pst.viewState<unknown, ChecksWrittenResult>({ function: 'checksActive' })).result.total).toEqual(
200_000
);
});

it('should not be able to write check', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ describe('Arweave Gateway interaction loader', () => {
const arweave = Arweave.init({ host: 'arweave.net', port: 443, protocol: 'https' });

const arLoader = new ArweaveGatewayBundledInteractionLoader(arweave, 'mainnet');
const wrLoader = new WarpGatewayContractDefinitionLoader(arweave, contractsCache, sourceCache, 'mainnet')
const wrLoader = new WarpGatewayContractDefinitionLoader(arweave, contractsCache, sourceCache, 'mainnet');
const withArLoader = WarpFactory.custom(arweave, { inMemory: true, dbLocation: '' }, 'mainnet')
.setInteractionsLoader(arLoader)
.setDefinitionLoader(wrLoader)
.build();
arLoader.warp = withArLoader;
wrLoader.warp = withArLoader;


const arResult = await withArLoader
.contract(EXAMPLE_CONTRACT_TX_ID)
.setEvaluationOptions({ allowBigInt: true })
Expand Down
17 changes: 12 additions & 5 deletions src/__tests__/unit/gateway-interactions.loader.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Arweave from 'arweave';
import { LexicographicalInteractionsSorter } from '../../core/modules/impl/LexicographicalInteractionsSorter';
import {ConfirmationStatus, WarpGatewayInteractionsLoader} from '../../core/modules/impl/WarpGatewayInteractionsLoader';
import {
ConfirmationStatus,
WarpGatewayInteractionsLoader
} from '../../core/modules/impl/WarpGatewayInteractionsLoader';
import { GQLNodeInterface } from '../../legacy/gqlResult';
import { LoggerFactory } from '../../logging/LoggerFactory';
import {WarpFactory} from "../../core/WarpFactory";
import { WarpFactory } from '../../core/WarpFactory';

const responseData = {
paging: {
Expand Down Expand Up @@ -122,12 +125,12 @@ describe('WarpGatewayInteractionsLoader -> load', () => {
expect(fetchMock).toHaveBeenCalledTimes(5);*/
});
it('should be called with confirmationStatus set to "confirmed"', async () => {
const loader = getLoader({confirmed: true});
const loader = getLoader({ confirmed: true });
await loader.load(contractId, fromBlockHeight, toBlockHeight);
expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true&confirmationStatus=confirmed`);
});
it('should be called with confirmationStatus set to "not_corrupted"', async () => {
const loader = getLoader({notCorrupted: true});
const loader = getLoader({ notCorrupted: true });
await loader.load(contractId, fromBlockHeight, toBlockHeight);
expect(fetchMock).toBeCalledWith(`${baseUrl}&page=1&fromSdk=true&confirmationStatus=not_corrupted`);
});
Expand All @@ -148,7 +151,11 @@ describe('WarpGatewayInteractionsLoader -> load', () => {
try {
await loader.load(contractId, fromBlockHeight, toBlockHeight);
} catch (e) {
expect(e).toEqual(new Error('Error while communicating with gateway: {"status":500,"ok":false,"body":{"message":"request fails"}}'));
expect(e).toEqual(
new Error(
'Error while communicating with gateway: {"status":500,"ok":false,"body":{"message":"request fails"}}'
)
);
}
});
});
Expand Down
3 changes: 1 addition & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import copy from 'fast-copy';
import {Buffer} from 'warp-isomorphic';
import { Buffer } from 'warp-isomorphic';

export const sleep = (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand Down Expand Up @@ -101,5 +101,4 @@ export async function getJsonResponse<T>(response: Promise<Response>): Promise<T
}
const result = await r.json();
return result as T;

}

0 comments on commit a946381

Please sign in to comment.