v1.4.19
Some checks failed
CI / build (push) Has been cancelled

This commit is contained in:
ppedziwiatr
2023-09-27 14:00:38 +02:00
parent d21d1213a6
commit 8e7157efee
3 changed files with 41 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "warp-contracts", "name": "warp-contracts",
"version": "1.4.18", "version": "1.4.19",
"description": "An implementation of the SmartWeave smart contract protocol.", "description": "An implementation of the SmartWeave smart contract protocol.",
"types": "./lib/types/index.d.ts", "types": "./lib/types/index.d.ts",
"main": "./lib/cjs/index.js", "main": "./lib/cjs/index.js",

View File

@@ -6,9 +6,9 @@ import path from 'path';
import { mineBlock } from '../_helpers'; import { mineBlock } from '../_helpers';
import { Contract } from '../../../contract/Contract'; import { Contract } from '../../../contract/Contract';
import { Warp } from '../../../core/Warp'; import { Warp } from '../../../core/Warp';
import { WarpFactory } from "../../../core/WarpFactory"; import { WarpFactory } from '../../../core/WarpFactory';
import { LoggerFactory } from '../../../logging/LoggerFactory'; 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. * This test verifies "deep" reads between contracts.
@@ -61,9 +61,15 @@ describe('Testing deep internal reads', () => {
({ jwk: wallet } = await warp.generateWallet()); ({ jwk: wallet } = await warp.generateWallet());
const leafSrc = fs.readFileSync(path.join(__dirname, '../data/nested-read/leaf-contract.js'), 'utf8'); 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 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({ ({ contractTxId: leafId } = await warp.deploy({
wallet, wallet,
@@ -101,24 +107,12 @@ describe('Testing deep internal reads', () => {
src: nodeSrc src: nodeSrc
})); }));
rootContract = warp rootContract = warp.contract(rootId).connect(wallet);
.contract(rootId) node20Contract = warp.contract(node20Id).connect(wallet);
.connect(wallet); node21Contract = warp.contract(node21Id).connect(wallet);
node20Contract = warp node22Contract = warp.contract(node22Id).connect(wallet);
.contract(node20Id) node1Contract = warp.contract(nod1Id).connect(wallet);
.connect(wallet); leafContract = warp.contract(leafId).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);
await mineBlock(warp); await mineBlock(warp);
@@ -158,20 +152,33 @@ describe('Testing deep internal reads', () => {
await mineBlock(warp); await mineBlock(warp);
await node21Contract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: leafId, contractTxId: 'asd' }); await node21Contract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: leafId, contractTxId: 'asd' });
await mineBlock(warp); 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 mineBlock(warp);
await node1Contract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: node21Id, contractTxId: 'asd' }); await node1Contract.writeInteraction({
function: 'readBalanceFrom',
tokenAddress: node21Id,
contractTxId: 'asd'
});
await mineBlock(warp); 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 mineBlock(warp);
await rootContract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: nod1Id, contractTxId: 'asd' }); await rootContract.writeInteraction({ function: 'readBalanceFrom', tokenAddress: nod1Id, contractTxId: 'asd' });
await mineBlock(warp); await mineBlock(warp);
const rootResult = await warp
const rootResult = await warp.pst(rootId) .pst(rootId)
.setEvaluationOptions({ .setEvaluationOptions({
cacheEveryNInteractions: 1, cacheEveryNInteractions: 1
}).readState(); })
.readState();
expect(rootResult.cachedValue.state.balances['asd']).toEqual(1100); expect(rootResult.cachedValue.state.balances['asd']).toEqual(1100);
const node20Result = await warp.pst(node20Id).readState(); const node20Result = await warp.pst(node20Id).readState();

View File

@@ -221,7 +221,7 @@ describe('Testing internal writes', () => {
async function currentContractEntries(contractTxId: string): Promise<[[string, string]]> { async function currentContractEntries(contractTxId: string): Promise<[[string, string]]> {
const storage: MemoryLevel<string, any> = await warp.stateEvaluator.getCache().storage(); 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(); return await sub.iterator().all();
} }
@@ -271,7 +271,9 @@ describe('Testing internal writes', () => {
expect(entries2.length).toEqual(5); expect(entries2.length).toEqual(5);
const lastCacheValue = await warp.stateEvaluator.getCache().getLast(calleeContract.txId()); const lastCacheValue = await warp.stateEvaluator.getCache().getLast(calleeContract.txId());
expect(lastCacheValue.cachedValue.state).toEqual(result1.cachedValue.state); 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; const blockHeight = (await warp.arweave.network.getInfo()).height;
expect(lastCacheValue.sortKey).toContain(`${blockHeight}`.padStart(12, '0')); expect(lastCacheValue.sortKey).toContain(`${blockHeight}`.padStart(12, '0'));
@@ -290,7 +292,6 @@ describe('Testing internal writes', () => {
const entries2 = await currentContractEntries(calleeContract.txId()); const entries2 = await currentContractEntries(calleeContract.txId());
expect(entries2.length).toEqual(7); expect(entries2.length).toEqual(7);
}); });
}); });
describe('with read state at the end', () => { describe('with read state at the end', () => {