feat: contract manifest - more descriptive errors
This commit is contained in:
@@ -96,7 +96,7 @@ describe('Evaluation options evaluator', () => {
|
|||||||
const result = new EvaluationOptionsEvaluator(contract2.evaluationOptions(), {
|
const result = new EvaluationOptionsEvaluator(contract2.evaluationOptions(), {
|
||||||
useVM2: false
|
useVM2: false
|
||||||
}).rootOptions;
|
}).rootOptions;
|
||||||
}).toThrow('Option {useVM2} differs, user: [true], manifest: [false]');
|
}).toThrow('Option {useVM2} differs. EvaluationOptions: [true], manifest: [false]. Use contract.setEvaluationOptions({useVM2: false) to evaluate contract state.');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should properly set foreign evaluation options - unsafeClient - allow', async () => {
|
it('should properly set foreign evaluation options - unsafeClient - allow', async () => {
|
||||||
|
|||||||
@@ -112,21 +112,17 @@ export class EvaluationOptionsEvaluator {
|
|||||||
*/
|
*/
|
||||||
constructor(userSetOptions: EvaluationOptions, manifestOptions: Partial<EvaluationOptions>) {
|
constructor(userSetOptions: EvaluationOptions, manifestOptions: Partial<EvaluationOptions>) {
|
||||||
if (manifestOptions) {
|
if (manifestOptions) {
|
||||||
|
const errors = [];
|
||||||
for (const k in manifestOptions) {
|
for (const k in manifestOptions) {
|
||||||
if (userSetOptions[k] !== manifestOptions[k]) {
|
if (userSetOptions[k] !== manifestOptions[k]) {
|
||||||
throw new Error(`Option {${k}} differs, user: [${userSetOptions[k]}], manifest: [${manifestOptions[k]}]`);
|
errors.push(
|
||||||
|
`Option {${k}} differs. EvaluationOptions: [${userSetOptions[k]}], manifest: [${manifestOptions[k]}]. Use contract.setEvaluationOptions({${k}: ${manifestOptions[k]}) to evaluate contract state.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (errors.length) {
|
||||||
/* if (userSetOptions.internalWrites !== undefined && (userSetOptions.internalWrites != manifestOptions.internalWrites)) {
|
throw new Error(errors.join('\n'));
|
||||||
throw new Error('User and contract manifest not compatible - internalWrites');
|
|
||||||
}
|
}
|
||||||
if (userSetOptions.unsafeClient && (manifestOptions.unsafeClient != userSetOptions.unsafeClient)) {
|
|
||||||
throw new Error('User and contract manifest not compatible - unsafeClient');
|
|
||||||
}
|
|
||||||
if (userSetOptions.throwOnInternalWriteError && (manifestOptions.throwOnInternalWriteError != userSetOptions.throwOnInternalWriteError)) {
|
|
||||||
throw new Error('User and contract manifest not compatible - throwOnInternalWriteError');
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rootOptions = Object.freeze(Object.assign({}, userSetOptions, manifestOptions || {}));
|
this.rootOptions = Object.freeze(Object.assign({}, userSetOptions, manifestOptions || {}));
|
||||||
|
|||||||
92
tools/bar.ts
92
tools/bar.ts
@@ -1,92 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
import { defaultCacheOptions, LoggerFactory, WarpFactory } from '../src';
|
|
||||||
|
|
||||||
let ownerWallet, owner;
|
|
||||||
|
|
||||||
let arlocal;
|
|
||||||
let warp;
|
|
||||||
let bar;
|
|
||||||
|
|
||||||
let contractTxId, initialState;
|
|
||||||
|
|
||||||
LoggerFactory.INST.logLevel('error');
|
|
||||||
LoggerFactory.INST.logLevel('debug', 'JsHandlerApi');
|
|
||||||
LoggerFactory.INST.logLevel('debug', 'AbstractContractHandler');
|
|
||||||
|
|
||||||
(async function evaluate() {
|
|
||||||
warp = WarpFactory.forMainnet({ ...defaultCacheOptions, inMemory: true });
|
|
||||||
|
|
||||||
({ jwk: ownerWallet, address: owner } = await warp.generateWallet());
|
|
||||||
|
|
||||||
bar = warp
|
|
||||||
.contract('VFr3Bk-uM-motpNNkkFg4lNW1BMmSfzqsVO551Ho4hA')
|
|
||||||
.setEvaluationOptions({
|
|
||||||
maxInteractionEvaluationTimeSeconds: 180,
|
|
||||||
internalWrites: true,
|
|
||||||
unsafeClient: 'skip',
|
|
||||||
allowBigInt: true,
|
|
||||||
useVM2: true
|
|
||||||
})
|
|
||||||
.connect(ownerWallet);
|
|
||||||
|
|
||||||
// const rawInteractions = await warp.interactionsLoader.load("VFr3Bk-uM-motpNNkkFg4lNW1BMmSfzqsVO551Ho4hA");
|
|
||||||
// var interactions = rawInteractions.reduce(function(map, obj) {
|
|
||||||
// map[obj.id] = obj;
|
|
||||||
// return map;
|
|
||||||
// }, {});
|
|
||||||
//console.log(interactions);
|
|
||||||
|
|
||||||
const failingContracts = {};
|
|
||||||
try {
|
|
||||||
const state = await bar.readState(
|
|
||||||
'000001043463,1666666263817,745f5b5c06b8d1859b6521e6df00d95dae2aeac70db4e8a3f233e618247000d7'
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
console.trace('Main script error catch', {
|
|
||||||
trace: JSON.parse(e.traceData),
|
|
||||||
uuid: e.uuid
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// const errors = state.cachedValue.errorMessages;
|
|
||||||
// const failedTxs = Object.keys(errors);
|
|
||||||
// let errNotEnoughBalance = 0;
|
|
||||||
// let errOthers = 0;
|
|
||||||
// let invalidTransfer = 0;
|
|
||||||
// let invalidValue = 0;
|
|
||||||
// failedTxs.forEach(txId => {
|
|
||||||
// if (errors[txId].includes("Caller balance not high enough")) {
|
|
||||||
// errNotEnoughBalance++;
|
|
||||||
// } else if (errors[txId].includes("Invalid token transfer.")) {
|
|
||||||
// invalidTransfer++;
|
|
||||||
// } else if (errors[txId].includes("Invalid value")) {
|
|
||||||
// invalidValue++;
|
|
||||||
// } else {
|
|
||||||
// console.log(errors[txId]);
|
|
||||||
// errOthers++;
|
|
||||||
// interactions[txId].tags.forEach(tag => {
|
|
||||||
// if (tag.name === 'Contract') {
|
|
||||||
// if (!failingContracts[tag.value]) {
|
|
||||||
// failingContracts[tag.value] = [];
|
|
||||||
// }
|
|
||||||
// failingContracts[tag.value].push(txId);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// })
|
|
||||||
// console.log("Not enough balance " + errNotEnoughBalance);
|
|
||||||
// console.log("Invalid transfer " + invalidTransfer);
|
|
||||||
// console.log("Invalid value " + invalidValue);
|
|
||||||
// console.log("Others " + errOthers);
|
|
||||||
// console.log(errors);
|
|
||||||
// console.log(failingContracts);
|
|
||||||
// console.log(Object.keys(contractTxId.cachedValue.validity).length);
|
|
||||||
const filename = './dump_' + new Date().getTime();
|
|
||||||
fs.writeFileSync(filename, bar.getCallStack().print());
|
|
||||||
// Object.keys(failingContracts).forEach(contractId => {
|
|
||||||
// console.log(contractId + " : " + failingContracts[contractId].length);
|
|
||||||
// })
|
|
||||||
})();
|
|
||||||
@@ -8,7 +8,7 @@ import {JWKInterface} from 'arweave/node/lib/wallet';
|
|||||||
async function main() {
|
async function main() {
|
||||||
let wallet: JWKInterface = readJSON('./.secrets/33F0QHcb22W7LwWR1iRC8Az1ntZG09XQ03YWuw2ABqA.json');
|
let wallet: JWKInterface = readJSON('./.secrets/33F0QHcb22W7LwWR1iRC8Az1ntZG09XQ03YWuw2ABqA.json');
|
||||||
LoggerFactory.INST.logLevel('error');
|
LoggerFactory.INST.logLevel('error');
|
||||||
LoggerFactory.INST.logLevel('debug', 'ExecutionContext');
|
//LoggerFactory.INST.logLevel('debug', 'ExecutionContext');
|
||||||
const logger = LoggerFactory.INST.create('deploy');
|
const logger = LoggerFactory.INST.create('deploy');
|
||||||
|
|
||||||
const arweave = Arweave.init({
|
const arweave = Arweave.init({
|
||||||
@@ -63,7 +63,7 @@ async function main() {
|
|||||||
});*/
|
});*/
|
||||||
|
|
||||||
const contract = warp.contract<any>(contractTxId)
|
const contract = warp.contract<any>(contractTxId)
|
||||||
.setEvaluationOptions({internalWrites: false, unsafeClient: 'throw'})
|
.setEvaluationOptions({internalWrites: false, unsafeClient: 'throw', allowBigInt: true})
|
||||||
.connect(wallet);
|
.connect(wallet);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@@ -90,7 +90,8 @@ async function main() {
|
|||||||
console.dir(cachedValue.state);
|
console.dir(cachedValue.state);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(e)
|
//logger.error(e)
|
||||||
|
throw e;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user