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

This commit is contained in:
ppe
2022-08-31 16:08:55 +02:00
parent fdd3f3888c
commit cd3d38edd9
5 changed files with 51 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "warp-contracts", "name": "warp-contracts",
"version": "1.2.0-rc.2", "version": "1.2.0",
"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

@@ -2,13 +2,13 @@
import fs from 'fs'; import fs from 'fs';
import ArLocal from 'arlocal'; import ArLocal from 'arlocal';
import {JWKInterface} from 'arweave/node/lib/wallet'; import { JWKInterface } from 'arweave/node/lib/wallet';
import path from 'path'; 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';
interface ExampleContractState { interface ExampleContractState {
counter: number; counter: number;
@@ -74,20 +74,20 @@ describe('Testing internal writes', () => {
async function deployContracts() { async function deployContracts() {
warp = WarpFactory.forLocal(port); warp = WarpFactory.forLocal(port);
({ jwk: wallet } = await warp.testing.generateWallet()) ({ jwk: wallet } = await warp.testing.generateWallet());
callingContractSrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8'); callingContractSrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
callingContractInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8'); callingContractInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');
calleeContractSrc = fs.readFileSync(path.join(__dirname, '../data/example-contract.js'), 'utf8'); calleeContractSrc = fs.readFileSync(path.join(__dirname, '../data/example-contract.js'), 'utf8');
calleeInitialState = fs.readFileSync(path.join(__dirname, '../data/example-contract-state.json'), 'utf8'); calleeInitialState = fs.readFileSync(path.join(__dirname, '../data/example-contract-state.json'), 'utf8');
({contractTxId: calleeTxId} = await warp.createContract.deploy({ ({ contractTxId: calleeTxId } = await warp.createContract.deploy({
wallet, wallet,
initState: calleeInitialState, initState: calleeInitialState,
src: calleeContractSrc src: calleeContractSrc
})); }));
({contractTxId: callingTxId} = await warp.createContract.deploy({ ({ contractTxId: callingTxId } = await warp.createContract.deploy({
wallet, wallet,
initState: callingContractInitialState, initState: callingContractInitialState,
src: callingContractSrc src: callingContractSrc
@@ -138,68 +138,68 @@ describe('Testing internal writes', () => {
}); });
it('should write direct interactions', async () => { it('should write direct interactions', async () => {
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(557); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(557);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(557); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(557);
}); });
it('should write one direct and one internal interaction', async () => { it('should write one direct and one internal interaction', async () => {
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(568); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(568);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(568); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(568);
}); });
it('should write another direct interaction', async () => { it('should write another direct interaction', async () => {
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(569); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(569);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(569); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(569);
}); });
it('should write double internal interaction with direct interaction', async () => { it('should write double internal interaction with direct interaction', async () => {
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(590); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(590);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(590); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(590);
}); });
it('should write combination of internal and direct interaction', async () => { it('should write combination of internal and direct interaction', async () => {
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(601); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(601);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(601); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(601);
}); });
it('should write combination of internal and direct interaction', async () => { it('should write combination of internal and direct interaction', async () => {
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(612); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(612);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(612); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(612);
}); });
it('should write combination of direct and internal interaction - at one block', async () => { it('should write combination of direct and internal interaction - at one block', async () => {
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(623); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(623);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(623); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(623);
}); });
it('should write combination of direct and internal interaction - on different blocks', async () => { it('should write combination of direct and internal interaction - on different blocks', async () => {
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(634); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(634);
expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(634); expect((await calleeContractVM.readState()).cachedValue.state.counter).toEqual(634);
@@ -217,40 +217,40 @@ describe('Testing internal writes', () => {
}); });
it('should properly write a combination of direct and internal interactions', async () => { it('should properly write a combination of direct and internal interactions', async () => {
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await callingContract.writeInteraction({function: 'writeContract', contractId: calleeTxId, amount: 10}); await callingContract.writeInteraction({ function: 'writeContract', contractId: calleeTxId, amount: 10 });
await mineBlock(warp); await mineBlock(warp);
await calleeContract.writeInteraction({function: 'add'}); await calleeContract.writeInteraction({ function: 'add' });
await mineBlock(warp); await mineBlock(warp);
expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(634); expect((await calleeContract.readState()).cachedValue.state.counter).toEqual(634);
@@ -285,7 +285,7 @@ describe('Testing internal writes', () => {
}); });
it('should auto throw on default settings', async () => { it('should auto throw on default settings', async () => {
const {originalTxId} = await callingContract.writeInteraction({ const { originalTxId } = await callingContract.writeInteraction({
function: 'writeContractAutoThrow', function: 'writeContractAutoThrow',
contractId: calleeTxId contractId: calleeTxId
}); });
@@ -299,7 +299,7 @@ describe('Testing internal writes', () => {
}); });
it('should not auto throw on default settings if IW call force to NOT throw an exception ', async () => { it('should not auto throw on default settings if IW call force to NOT throw an exception ', async () => {
const {originalTxId} = await callingContract.writeInteraction({ const { originalTxId } = await callingContract.writeInteraction({
function: 'writeContractForceNoAutoThrow', function: 'writeContractForceNoAutoThrow',
contractId: calleeTxId contractId: calleeTxId
}); });
@@ -317,7 +317,7 @@ describe('Testing internal writes', () => {
throwOnInternalWriteError: false throwOnInternalWriteError: false
}); });
const {originalTxId} = await callingContract.writeInteraction({ const { originalTxId } = await callingContract.writeInteraction({
function: 'writeContractAutoThrow', function: 'writeContractAutoThrow',
contractId: calleeTxId contractId: calleeTxId
}); });
@@ -335,7 +335,7 @@ describe('Testing internal writes', () => {
throwOnInternalWriteError: true throwOnInternalWriteError: true
}); });
const {originalTxId} = await callingContract.writeInteraction({ const { originalTxId } = await callingContract.writeInteraction({
function: 'writeContractAutoThrow', function: 'writeContractAutoThrow',
contractId: calleeTxId contractId: calleeTxId
}); });
@@ -355,7 +355,7 @@ describe('Testing internal writes', () => {
throwOnInternalWriteError: false throwOnInternalWriteError: false
}); });
const {originalTxId} = await callingContract.writeInteraction({ const { originalTxId } = await callingContract.writeInteraction({
function: 'writeContractForceAutoThrow', function: 'writeContractForceAutoThrow',
contractId: calleeTxId contractId: calleeTxId
}); });
@@ -375,7 +375,7 @@ describe('Testing internal writes', () => {
throwOnInternalWriteError: true throwOnInternalWriteError: true
}); });
const {originalTxId} = await callingContract.writeInteraction({ const { originalTxId } = await callingContract.writeInteraction({
function: 'writeContractForceNoAutoThrow', function: 'writeContractForceNoAutoThrow',
contractId: calleeTxId contractId: calleeTxId
}); });
@@ -386,6 +386,5 @@ describe('Testing internal writes', () => {
expect(result.cachedValue.errorMessages[originalTxId]).toBeUndefined(); expect(result.cachedValue.errorMessages[originalTxId]).toBeUndefined();
expect(result.cachedValue.state.errorCounter).toEqual(3); expect(result.cachedValue.state.errorCounter).toEqual(3);
}); });
}); });
}); });

View File

@@ -85,7 +85,7 @@ describe('Testing internal writes', () => {
async function deployContracts() { async function deployContracts() {
warp = WarpFactory.forLocal(port); warp = WarpFactory.forLocal(port);
({ jwk: wallet } = await warp.testing.generateWallet()) ({ jwk: wallet } = await warp.testing.generateWallet());
callingContractSrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8'); callingContractSrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
callingContractInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8'); callingContractInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');

View File

@@ -86,7 +86,7 @@ describe('Testing internal writes', () => {
async function deployContracts() { async function deployContracts() {
warp = WarpFactory.forLocal(port); warp = WarpFactory.forLocal(port);
({ jwk: wallet } = await warp.testing.generateWallet()) ({ jwk: wallet } = await warp.testing.generateWallet());
contractASrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8'); contractASrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
contractAInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8'); contractAInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');

View File

@@ -80,7 +80,7 @@ describe('Testing internal writes', () => {
async function deployContracts() { async function deployContracts() {
warp = WarpFactory.forLocal(port); warp = WarpFactory.forLocal(port);
({ jwk: wallet } = await warp.testing.generateWallet()) ({ jwk: wallet } = await warp.testing.generateWallet());
contractASrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8'); contractASrc = fs.readFileSync(path.join(__dirname, '../data/writing-contract.js'), 'utf8');
contractAInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8'); contractAInitialState = fs.readFileSync(path.join(__dirname, '../data/writing-contract-state.json'), 'utf8');