Skip to content

Commit

Permalink
v1.4.19
Browse files Browse the repository at this point in the history
  • Loading branch information
ppedziwiatr committed Sep 27, 2023
1 parent d21d121 commit 8e7157e
Show file tree
Hide file tree
Showing 3 changed files with 41 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.18",
"version": "1.4.19",
"description": "An implementation of the SmartWeave smart contract protocol.",
"types": "./lib/types/index.d.ts",
"main": "./lib/cjs/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import path from 'path';
import { mineBlock } from '../_helpers';
import { Contract } from '../../../contract/Contract';
import { Warp } from '../../../core/Warp';
import { WarpFactory } from "../../../core/WarpFactory";
import { WarpFactory } from '../../../core/WarpFactory';
import { LoggerFactory } from '../../../logging/LoggerFactory';
import { DeployPlugin } from "warp-contracts-plugin-deploy";
import { DeployPlugin } from 'warp-contracts-plugin-deploy';

/**
* This test verifies "deep" reads between contracts.
Expand Down Expand Up @@ -61,9 +61,15 @@ describe('Testing deep internal reads', () => {
({ jwk: wallet } = await warp.generateWallet());

const leafSrc = fs.readFileSync(path.join(__dirname, '../data/nested-read/leaf-contract.js'), 'utf8');
const leafState = fs.readFileSync(path.join(__dirname, '../data/nested-read/leaf-contract-init-state.json'), 'utf8');
const leafState = fs.readFileSync(
path.join(__dirname, '../data/nested-read/leaf-contract-init-state.json'),
'utf8'
);
const nodeSrc = fs.readFileSync(path.join(__dirname, '../data/nested-read/node-contract.js'), 'utf8');
const nodeState = fs.readFileSync(path.join(__dirname, '../data/nested-read/node-contract-init-state.json'), 'utf8');
const nodeState = fs.readFileSync(
path.join(__dirname, '../data/nested-read/node-contract-init-state.json'),
'utf8'
);

({ contractTxId: leafId } = await warp.deploy({
wallet,
Expand Down Expand Up @@ -101,24 +107,12 @@ describe('Testing deep internal reads', () => {
src: nodeSrc
}));

rootContract = warp
.contract(rootId)
.connect(wallet);
node20Contract = warp
.contract(node20Id)
.connect(wallet);
node21Contract = warp
.contract(node21Id)
.connect(wallet);
node22Contract = warp
.contract(node22Id)
.connect(wallet);
node1Contract = warp
.contract(nod1Id)
.connect(wallet);
leafContract = warp
.contract(leafId)
.connect(wallet);
rootContract = warp.contract(rootId).connect(wallet);
node20Contract = warp.contract(node20Id).connect(wallet);
node21Contract = warp.contract(node21Id).connect(wallet);
node22Contract = warp.contract(node22Id).connect(wallet);
node1Contract = warp.contract(nod1Id).connect(wallet);
leafContract = warp.contract(leafId).connect(wallet);

await mineBlock(warp);
await mineBlock(warp);
Expand Down Expand Up @@ -158,20 +152,33 @@ describe('Testing deep internal reads', () => {
await mineBlock(warp);
await node21Contract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: leafId, contractTxId: 'asd' });
await mineBlock(warp);
await node1Contract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: node20Id, contractTxId: 'asd' });
await node1Contract.writeInteraction({
function: 'readBalanceFrom',
tokenAddress: node20Id,
contractTxId: 'asd'
});
await mineBlock(warp);
await node1Contract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: node21Id, contractTxId: 'asd' });
await node1Contract.writeInteraction({
function: 'readBalanceFrom',
tokenAddress: node21Id,
contractTxId: 'asd'
});
await mineBlock(warp);
await node1Contract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: node22Id, contractTxId: 'asd' });
await node1Contract.writeInteraction({
function: 'readBalanceFrom',
tokenAddress: node22Id,
contractTxId: 'asd'
});
await mineBlock(warp);
await rootContract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: nod1Id, contractTxId: 'asd' });
await mineBlock(warp);


const rootResult = await warp.pst(rootId)
const rootResult = await warp
.pst(rootId)
.setEvaluationOptions({
cacheEveryNInteractions: 1,
}).readState();
cacheEveryNInteractions: 1
})
.readState();
expect(rootResult.cachedValue.state.balances['asd']).toEqual(1100);

const node20Result = await warp.pst(node20Id).readState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe('Testing internal writes', () => {

async function currentContractEntries(contractTxId: string): Promise<[[string, string]]> {
const storage: MemoryLevel<string, any> = await warp.stateEvaluator.getCache().storage();
const sub = storage.sublevel(contractTxId, { valueEncoding: "json" });
const sub = storage.sublevel(contractTxId, { valueEncoding: 'json' });
return await sub.iterator().all();
}

Expand Down Expand Up @@ -271,7 +271,9 @@ describe('Testing internal writes', () => {
expect(entries2.length).toEqual(5);
const lastCacheValue = await warp.stateEvaluator.getCache().getLast(calleeContract.txId());
expect(lastCacheValue.cachedValue.state).toEqual(result1.cachedValue.state);
expect(Object.keys(result1.cachedValue.errorMessages).length + 1).toEqual(Object.keys(lastCacheValue.cachedValue.errorMessages).length);
expect(Object.keys(result1.cachedValue.errorMessages).length + 1).toEqual(
Object.keys(lastCacheValue.cachedValue.errorMessages).length
);

const blockHeight = (await warp.arweave.network.getInfo()).height;
expect(lastCacheValue.sortKey).toContain(`${blockHeight}`.padStart(12, '0'));
Expand All @@ -290,7 +292,6 @@ describe('Testing internal writes', () => {
const entries2 = await currentContractEntries(calleeContract.txId());
expect(entries2.length).toEqual(7);
});

});

describe('with read state at the end', () => {
Expand Down

0 comments on commit 8e7157e

Please sign in to comment.