recon-generate 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -0
- package/dist/generator.d.ts +52 -0
- package/dist/generator.js +512 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +169 -0
- package/dist/templateManager.d.ts +14 -0
- package/dist/templateManager.js +236 -0
- package/dist/templates/before-after.d.ts +1 -0
- package/dist/templates/before-after.js +37 -0
- package/dist/templates/crytic-tester.d.ts +1 -0
- package/dist/templates/crytic-tester.js +23 -0
- package/dist/templates/crytic-to-foundry.d.ts +1 -0
- package/dist/templates/crytic-to-foundry.js +32 -0
- package/dist/templates/echidna-config.d.ts +1 -0
- package/dist/templates/echidna-config.js +20 -0
- package/dist/templates/halmos-config.d.ts +1 -0
- package/dist/templates/halmos-config.js +14 -0
- package/dist/templates/handlebars-helpers.d.ts +2 -0
- package/dist/templates/handlebars-helpers.js +142 -0
- package/dist/templates/index.d.ts +14 -0
- package/dist/templates/index.js +29 -0
- package/dist/templates/medusa-config.d.ts +1 -0
- package/dist/templates/medusa-config.js +112 -0
- package/dist/templates/properties.d.ts +1 -0
- package/dist/templates/properties.js +18 -0
- package/dist/templates/setup.d.ts +1 -0
- package/dist/templates/setup.js +55 -0
- package/dist/templates/target-functions.d.ts +1 -0
- package/dist/templates/target-functions.js +37 -0
- package/dist/templates/targets/admin-targets.d.ts +1 -0
- package/dist/templates/targets/admin-targets.js +33 -0
- package/dist/templates/targets/doomsday-targets.d.ts +1 -0
- package/dist/templates/targets/doomsday-targets.js +33 -0
- package/dist/templates/targets/managers-targets.d.ts +1 -0
- package/dist/templates/targets/managers-targets.js +61 -0
- package/dist/templates/targets/targets.d.ts +1 -0
- package/dist/templates/targets/targets.js +35 -0
- package/dist/types.d.ts +45 -0
- package/dist/types.js +14 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +106 -0
- package/package.json +30 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerHelpers = registerHelpers;
|
|
4
|
+
const case_1 = require("case");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
function capitalizeFirstLetter(string) {
|
|
7
|
+
if (string.length === 0) {
|
|
8
|
+
return string;
|
|
9
|
+
}
|
|
10
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
11
|
+
}
|
|
12
|
+
function getUsableInternalType(internalType) {
|
|
13
|
+
if (internalType.split(" ").length > 1) {
|
|
14
|
+
return internalType.split(" ")[1];
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return internalType;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function conditionallyAddMemoryLocation(type, internalType) {
|
|
21
|
+
if (type.indexOf("[") !== -1) {
|
|
22
|
+
if (internalType.startsWith("struct ") || internalType.startsWith("enum ") || internalType.startsWith("contract ")) {
|
|
23
|
+
const usable = getUsableInternalType(internalType);
|
|
24
|
+
return `${usable} memory`;
|
|
25
|
+
}
|
|
26
|
+
return `${type} memory`;
|
|
27
|
+
}
|
|
28
|
+
if (internalType.startsWith("struct ") || internalType.startsWith("enum ") || internalType.startsWith("contract ")) {
|
|
29
|
+
return `${getUsableInternalType(internalType)}${internalType.startsWith("struct ") ? " memory" : ""}`;
|
|
30
|
+
}
|
|
31
|
+
if (type === "bytes" || type === "string") {
|
|
32
|
+
return `${type} memory`;
|
|
33
|
+
}
|
|
34
|
+
return internalType || type;
|
|
35
|
+
}
|
|
36
|
+
function extractType(inputOrOutput) {
|
|
37
|
+
if (inputOrOutput.internalType) {
|
|
38
|
+
return inputOrOutput.internalType;
|
|
39
|
+
}
|
|
40
|
+
return inputOrOutput.type;
|
|
41
|
+
}
|
|
42
|
+
function registerHelpers(handlebars) {
|
|
43
|
+
handlebars.registerHelper('snake', function (str) {
|
|
44
|
+
return (0, case_1.snake)(str);
|
|
45
|
+
});
|
|
46
|
+
handlebars.registerHelper('scream', function (str) {
|
|
47
|
+
return (0, case_1.snake)(str).toUpperCase();
|
|
48
|
+
});
|
|
49
|
+
handlebars.registerHelper('camel', function (str) {
|
|
50
|
+
return (0, case_1.camel)(str);
|
|
51
|
+
});
|
|
52
|
+
handlebars.registerHelper('pascal', function (str) {
|
|
53
|
+
return (0, case_1.pascal)(str);
|
|
54
|
+
});
|
|
55
|
+
handlebars.registerHelper('functionDefinition', function ({ contractName, abi, actor, mode }) {
|
|
56
|
+
contractName = (0, case_1.camel)(contractName);
|
|
57
|
+
let modifiers = [];
|
|
58
|
+
if (abi.stateMutability === 'payable') {
|
|
59
|
+
modifiers.push('payable');
|
|
60
|
+
}
|
|
61
|
+
if (actor === types_1.Actor.ADMIN) {
|
|
62
|
+
modifiers.push('asAdmin');
|
|
63
|
+
}
|
|
64
|
+
else if (actor === types_1.Actor.ACTOR) {
|
|
65
|
+
modifiers.push('asActor');
|
|
66
|
+
}
|
|
67
|
+
const valueStr = abi.stateMutability === 'payable' ? '{value: msg.value}' : '';
|
|
68
|
+
const modifiersStr = modifiers.length ? modifiers.join(' ') + ' ' : '';
|
|
69
|
+
const hasOutputs = abi.outputs && abi.outputs.length > 0;
|
|
70
|
+
const outputs = abi.outputs && abi.outputs.length > 0
|
|
71
|
+
? abi.outputs
|
|
72
|
+
.map((output, index) => `${conditionallyAddMemoryLocation(output.type, extractType(output))} ${output.name !== "" ? output.name : `value${index}`};`)
|
|
73
|
+
.join("\n ")
|
|
74
|
+
: "";
|
|
75
|
+
const returnTypes = abi.outputs && abi.outputs.length > 0
|
|
76
|
+
? abi.outputs
|
|
77
|
+
.map((output, index) => `${conditionallyAddMemoryLocation(output.type, extractType(output))} ${output.name !== ""
|
|
78
|
+
? `temp${capitalizeFirstLetter(output.name)}`
|
|
79
|
+
: `tempValue${index}`}`)
|
|
80
|
+
.join(", ")
|
|
81
|
+
: "";
|
|
82
|
+
const assignValues = abi.outputs && abi.outputs.length > 0
|
|
83
|
+
? abi.outputs
|
|
84
|
+
.map((output, index) => `${output.name !== "" ? output.name : `value${index}`} = ${output.name !== ""
|
|
85
|
+
? `temp${capitalizeFirstLetter(output.name)}`
|
|
86
|
+
: `tempValue${index}`};`)
|
|
87
|
+
.join("\n ")
|
|
88
|
+
: "";
|
|
89
|
+
if (mode === types_1.Mode.NORMAL || mode === types_1.Mode.FAIL) {
|
|
90
|
+
return `
|
|
91
|
+
function ${contractName}_${abi.name}(${abi.inputs
|
|
92
|
+
.map((input) => `${conditionallyAddMemoryLocation(input.type, extractType(input))} ${input.name}`)
|
|
93
|
+
.join(", ")}) public ${modifiersStr}{
|
|
94
|
+
${contractName}.${abi.name}${valueStr}(${abi.inputs
|
|
95
|
+
.map((input) => input.name ? input.name : getDefaultValue(input.type))
|
|
96
|
+
.join(", ")});${mode === 'fail'
|
|
97
|
+
? `
|
|
98
|
+
t(false, "${contractName}_${abi.name}");`
|
|
99
|
+
: ""}
|
|
100
|
+
}`;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return `
|
|
104
|
+
function ${contractName}_${abi.name}(${abi.inputs
|
|
105
|
+
.map((input) => `${conditionallyAddMemoryLocation(input.type, extractType(input))} ${input.name}`)
|
|
106
|
+
.join(", ")}) public ${modifiersStr}{
|
|
107
|
+
${hasOutputs ? `${outputs}
|
|
108
|
+
try ${contractName}.${abi.name}${valueStr}(${abi.inputs
|
|
109
|
+
.map((input) => input.name ? input.name : getDefaultValue(input.type))
|
|
110
|
+
.join(", ")}) returns (${returnTypes}) {
|
|
111
|
+
${assignValues}
|
|
112
|
+
}`
|
|
113
|
+
: `try ${contractName}.${abi.name}(${abi.inputs
|
|
114
|
+
.map((input) => input.name ? input.name : getDefaultValue(input.type))
|
|
115
|
+
.join(", ")}) {}`} catch {
|
|
116
|
+
${hasOutputs ? " " : " "}t(false, "${contractName}_${abi.name}");
|
|
117
|
+
${hasOutputs ? " " : " "}}
|
|
118
|
+
}`;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function getDefaultValue(type) {
|
|
123
|
+
if (type === "address") {
|
|
124
|
+
return "address(0)";
|
|
125
|
+
}
|
|
126
|
+
else if (type.startsWith("uint") || type.startsWith("int")) {
|
|
127
|
+
return "0";
|
|
128
|
+
}
|
|
129
|
+
else if (type === "bool") {
|
|
130
|
+
return "false";
|
|
131
|
+
}
|
|
132
|
+
else if (type === "string") {
|
|
133
|
+
return '""';
|
|
134
|
+
}
|
|
135
|
+
else if (type === "bytes") {
|
|
136
|
+
return 'bytes("")';
|
|
137
|
+
}
|
|
138
|
+
else if (type.startsWith("bytes")) {
|
|
139
|
+
return `${type}("")`;
|
|
140
|
+
}
|
|
141
|
+
return '"__HandleMe__"';
|
|
142
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { echidnaConfigTemplate } from './echidna-config';
|
|
2
|
+
import { halmosConfigTemplate } from './halmos-config';
|
|
3
|
+
import { medusaConfigTemplate } from './medusa-config';
|
|
4
|
+
import { beforeAfterTemplate } from './before-after';
|
|
5
|
+
import { cryticTesterTemplate } from './crytic-tester';
|
|
6
|
+
import { cryticToFoundryTemplate } from './crytic-to-foundry';
|
|
7
|
+
import { propertiesTemplate } from './properties';
|
|
8
|
+
import { setupTemplate } from './setup';
|
|
9
|
+
import { targetFunctionsTemplate } from './target-functions';
|
|
10
|
+
import { adminTargetsTemplate } from './targets/admin-targets';
|
|
11
|
+
import { doomsdayTargetsTemplate } from './targets/doomsday-targets';
|
|
12
|
+
import { managersTargetsTemplate } from './targets/managers-targets';
|
|
13
|
+
import { targetsTemplate } from './targets/targets';
|
|
14
|
+
export { echidnaConfigTemplate, halmosConfigTemplate, medusaConfigTemplate, beforeAfterTemplate, cryticTesterTemplate, cryticToFoundryTemplate, propertiesTemplate, setupTemplate, targetFunctionsTemplate, adminTargetsTemplate, doomsdayTargetsTemplate, managersTargetsTemplate, targetsTemplate, };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.targetsTemplate = exports.managersTargetsTemplate = exports.doomsdayTargetsTemplate = exports.adminTargetsTemplate = exports.targetFunctionsTemplate = exports.setupTemplate = exports.propertiesTemplate = exports.cryticToFoundryTemplate = exports.cryticTesterTemplate = exports.beforeAfterTemplate = exports.medusaConfigTemplate = exports.halmosConfigTemplate = exports.echidnaConfigTemplate = void 0;
|
|
4
|
+
const echidna_config_1 = require("./echidna-config");
|
|
5
|
+
Object.defineProperty(exports, "echidnaConfigTemplate", { enumerable: true, get: function () { return echidna_config_1.echidnaConfigTemplate; } });
|
|
6
|
+
const halmos_config_1 = require("./halmos-config");
|
|
7
|
+
Object.defineProperty(exports, "halmosConfigTemplate", { enumerable: true, get: function () { return halmos_config_1.halmosConfigTemplate; } });
|
|
8
|
+
const medusa_config_1 = require("./medusa-config");
|
|
9
|
+
Object.defineProperty(exports, "medusaConfigTemplate", { enumerable: true, get: function () { return medusa_config_1.medusaConfigTemplate; } });
|
|
10
|
+
const before_after_1 = require("./before-after");
|
|
11
|
+
Object.defineProperty(exports, "beforeAfterTemplate", { enumerable: true, get: function () { return before_after_1.beforeAfterTemplate; } });
|
|
12
|
+
const crytic_tester_1 = require("./crytic-tester");
|
|
13
|
+
Object.defineProperty(exports, "cryticTesterTemplate", { enumerable: true, get: function () { return crytic_tester_1.cryticTesterTemplate; } });
|
|
14
|
+
const crytic_to_foundry_1 = require("./crytic-to-foundry");
|
|
15
|
+
Object.defineProperty(exports, "cryticToFoundryTemplate", { enumerable: true, get: function () { return crytic_to_foundry_1.cryticToFoundryTemplate; } });
|
|
16
|
+
const properties_1 = require("./properties");
|
|
17
|
+
Object.defineProperty(exports, "propertiesTemplate", { enumerable: true, get: function () { return properties_1.propertiesTemplate; } });
|
|
18
|
+
const setup_1 = require("./setup");
|
|
19
|
+
Object.defineProperty(exports, "setupTemplate", { enumerable: true, get: function () { return setup_1.setupTemplate; } });
|
|
20
|
+
const target_functions_1 = require("./target-functions");
|
|
21
|
+
Object.defineProperty(exports, "targetFunctionsTemplate", { enumerable: true, get: function () { return target_functions_1.targetFunctionsTemplate; } });
|
|
22
|
+
const admin_targets_1 = require("./targets/admin-targets");
|
|
23
|
+
Object.defineProperty(exports, "adminTargetsTemplate", { enumerable: true, get: function () { return admin_targets_1.adminTargetsTemplate; } });
|
|
24
|
+
const doomsday_targets_1 = require("./targets/doomsday-targets");
|
|
25
|
+
Object.defineProperty(exports, "doomsdayTargetsTemplate", { enumerable: true, get: function () { return doomsday_targets_1.doomsdayTargetsTemplate; } });
|
|
26
|
+
const managers_targets_1 = require("./targets/managers-targets");
|
|
27
|
+
Object.defineProperty(exports, "managersTargetsTemplate", { enumerable: true, get: function () { return managers_targets_1.managersTargetsTemplate; } });
|
|
28
|
+
const targets_1 = require("./targets/targets");
|
|
29
|
+
Object.defineProperty(exports, "targetsTemplate", { enumerable: true, get: function () { return targets_1.targetsTemplate; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const medusaConfigTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.medusaConfigTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("./handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.medusaConfigTemplate = handlebars_1.default.compile(`{
|
|
11
|
+
"fuzzing": {
|
|
12
|
+
"workers": 16,
|
|
13
|
+
"workerResetLimit": 50,
|
|
14
|
+
"timeout": 0,
|
|
15
|
+
"testLimit": 0,
|
|
16
|
+
"callSequenceLength": 100,
|
|
17
|
+
"corpusDirectory": "medusa",
|
|
18
|
+
"coverageEnabled": true,
|
|
19
|
+
"deploymentOrder": [
|
|
20
|
+
|
|
21
|
+
],
|
|
22
|
+
"targetContracts": [
|
|
23
|
+
"{{cryticTesterName}}"
|
|
24
|
+
],
|
|
25
|
+
"targetContractsBalances": [
|
|
26
|
+
"0x27b46536c66c8e3000000"
|
|
27
|
+
],
|
|
28
|
+
"predeployedContracts": {
|
|
29
|
+
"{{cryticTesterName}}": "0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496"
|
|
30
|
+
},
|
|
31
|
+
"constructorArgs": {},
|
|
32
|
+
"deployerAddress": "0xf5e4fFeB7d2183B61753AA4074d72E51873C1D0a",
|
|
33
|
+
"senderAddresses": [
|
|
34
|
+
"0x10000",
|
|
35
|
+
"0x20000",
|
|
36
|
+
"0x30000"
|
|
37
|
+
],
|
|
38
|
+
"blockNumberDelayMax": 60480,
|
|
39
|
+
"blockTimestampDelayMax": 604800,
|
|
40
|
+
"blockGasLimit": 125000000,
|
|
41
|
+
"transactionGasLimit": 12500000,
|
|
42
|
+
"testing": {
|
|
43
|
+
"stopOnFailedTest": false,
|
|
44
|
+
"stopOnFailedContractMatching": false,
|
|
45
|
+
"stopOnNoTests": true,
|
|
46
|
+
"testAllContracts": false,
|
|
47
|
+
"traceAll": false,
|
|
48
|
+
"assertionTesting": {
|
|
49
|
+
"enabled": true,
|
|
50
|
+
"testViewMethods": true,
|
|
51
|
+
"panicCodeConfig": {
|
|
52
|
+
"failOnCompilerInsertedPanic": false,
|
|
53
|
+
"failOnAssertion": true,
|
|
54
|
+
"failOnArithmeticUnderflow": false,
|
|
55
|
+
"failOnDivideByZero": false,
|
|
56
|
+
"failOnEnumTypeConversionOutOfBounds": false,
|
|
57
|
+
"failOnIncorrectStorageAccess": false,
|
|
58
|
+
"failOnPopEmptyArray": false,
|
|
59
|
+
"failOnOutOfBoundsArrayAccess": false,
|
|
60
|
+
"failOnAllocateTooMuchMemory": false,
|
|
61
|
+
"failOnCallUninitializedVariable": false
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"propertyTesting": {
|
|
65
|
+
"enabled": true,
|
|
66
|
+
"testPrefixes": [
|
|
67
|
+
"echidna_"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"optimizationTesting": {
|
|
71
|
+
"enabled": false,
|
|
72
|
+
"testPrefixes": [
|
|
73
|
+
"optimize_"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"chainConfig": {
|
|
78
|
+
"codeSizeCheckDisabled": true,
|
|
79
|
+
"cheatCodes": {
|
|
80
|
+
"cheatCodesEnabled": true,
|
|
81
|
+
"enableFFI": false
|
|
82
|
+
},
|
|
83
|
+
"skipAccountChecks": true,
|
|
84
|
+
"forkConfig": {
|
|
85
|
+
"forkModeEnabled": false,
|
|
86
|
+
"rpcUrl": "",
|
|
87
|
+
"rpcBlock": 1,
|
|
88
|
+
"poolSize": 20
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"compilation": {
|
|
93
|
+
"platform": "crytic-compile",
|
|
94
|
+
"platformConfig": {
|
|
95
|
+
"target": ".",
|
|
96
|
+
"solcVersion": "",
|
|
97
|
+
"exportDirectory": "",
|
|
98
|
+
"args": [
|
|
99
|
+
"--foundry-compile-all"
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"slither": {
|
|
104
|
+
"useSlither": true,
|
|
105
|
+
"cachePath": "slither_results.json",
|
|
106
|
+
"args": []
|
|
107
|
+
},
|
|
108
|
+
"logging": {
|
|
109
|
+
"level": "info",
|
|
110
|
+
"logDirectory": ""
|
|
111
|
+
}
|
|
112
|
+
}`, { noEscape: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const propertiesTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.propertiesTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("./handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.propertiesTemplate = handlebars_1.default.compile(`// SPDX-License-Identifier: GPL-2.0
|
|
11
|
+
pragma solidity ^0.8.0;
|
|
12
|
+
|
|
13
|
+
import {Asserts} from "@chimera/Asserts.sol";
|
|
14
|
+
import {BeforeAfter} from "./BeforeAfter.sol";
|
|
15
|
+
|
|
16
|
+
abstract contract Properties is BeforeAfter, Asserts {
|
|
17
|
+
|
|
18
|
+
}`, { noEscape: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setupTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setupTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("./handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.setupTemplate = handlebars_1.default.compile(`// SPDX-License-Identifier: GPL-2.0
|
|
11
|
+
pragma solidity ^0.8.0;
|
|
12
|
+
|
|
13
|
+
// Chimera deps
|
|
14
|
+
import {BaseSetup} from "@chimera/BaseSetup.sol";
|
|
15
|
+
import {vm} from "@chimera/Hevm.sol";
|
|
16
|
+
|
|
17
|
+
// Managers
|
|
18
|
+
import {ActorManager} from "@recon/ActorManager.sol";
|
|
19
|
+
import {AssetManager} from "@recon/AssetManager.sol";
|
|
20
|
+
|
|
21
|
+
// Helpers
|
|
22
|
+
import {Utils} from "@recon/Utils.sol";
|
|
23
|
+
|
|
24
|
+
// Your deps
|
|
25
|
+
{{#each contracts}}
|
|
26
|
+
import "{{this.path}}";
|
|
27
|
+
{{/each}}
|
|
28
|
+
|
|
29
|
+
abstract contract Setup is BaseSetup, ActorManager, AssetManager, Utils {
|
|
30
|
+
{{#each contracts}}
|
|
31
|
+
{{this.name}} {{camel this.name}};
|
|
32
|
+
{{/each}}
|
|
33
|
+
|
|
34
|
+
/// === Setup === ///
|
|
35
|
+
/// This contains all calls to be performed in the tester constructor, both for Echidna and Foundry
|
|
36
|
+
function setup() internal virtual override {
|
|
37
|
+
{{#each contracts}}
|
|
38
|
+
{{camel this.name}} = new {{this.name}}(); // TODO: Add parameters here
|
|
39
|
+
{{/each}}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// === MODIFIERS === ///
|
|
43
|
+
/// Prank admin and actor
|
|
44
|
+
|
|
45
|
+
modifier asAdmin {
|
|
46
|
+
vm.prank(address(this));
|
|
47
|
+
_;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
modifier asActor {
|
|
51
|
+
vm.prank(address(_getActor()));
|
|
52
|
+
_;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`, { noEscape: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const targetFunctionsTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.targetFunctionsTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("./handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.targetFunctionsTemplate = handlebars_1.default.compile(`// SPDX-License-Identifier: GPL-2.0
|
|
11
|
+
pragma solidity ^0.8.0;
|
|
12
|
+
|
|
13
|
+
// Chimera deps
|
|
14
|
+
import {vm} from "@chimera/Hevm.sol";
|
|
15
|
+
|
|
16
|
+
// Helpers
|
|
17
|
+
import {Panic} from "@recon/Panic.sol";
|
|
18
|
+
|
|
19
|
+
// Targets
|
|
20
|
+
// NOTE: Always import and apply them in alphabetical order, so much easier to debug!
|
|
21
|
+
{{#each contracts}}
|
|
22
|
+
import { {{pascal this}}Targets } from "./targets/{{pascal this}}Targets.sol";
|
|
23
|
+
{{/each}}
|
|
24
|
+
|
|
25
|
+
abstract contract TargetFunctions is
|
|
26
|
+
{{#each contracts}}{{pascal this}}Targets{{#unless @last}},
|
|
27
|
+
{{/unless}}{{/each}}
|
|
28
|
+
{
|
|
29
|
+
/// CUSTOM TARGET FUNCTIONS - Add your own target functions here ///
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/// AUTO GENERATED TARGET FUNCTIONS - WARNING: DO NOT DELETE OR MODIFY THIS LINE ///
|
|
33
|
+
{{#each functions}}
|
|
34
|
+
{{functionDefinition this}}
|
|
35
|
+
{{/each}}
|
|
36
|
+
}
|
|
37
|
+
`, { noEscape: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const adminTargetsTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.adminTargetsTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("../handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.adminTargetsTemplate = handlebars_1.default.compile(`// SPDX-License-Identifier: GPL-2.0
|
|
11
|
+
pragma solidity ^0.8.0;
|
|
12
|
+
|
|
13
|
+
import {BaseTargetFunctions} from "@chimera/BaseTargetFunctions.sol";
|
|
14
|
+
import {BeforeAfter} from "../BeforeAfter.sol";
|
|
15
|
+
import {Properties} from "../Properties.sol";
|
|
16
|
+
// Chimera deps
|
|
17
|
+
import {vm} from "@chimera/Hevm.sol";
|
|
18
|
+
|
|
19
|
+
// Helpers
|
|
20
|
+
import {Panic} from "@recon/Panic.sol";
|
|
21
|
+
|
|
22
|
+
abstract contract AdminTargets is
|
|
23
|
+
BaseTargetFunctions,
|
|
24
|
+
Properties
|
|
25
|
+
{
|
|
26
|
+
/// CUSTOM TARGET FUNCTIONS - Add your own target functions here ///
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/// AUTO GENERATED TARGET FUNCTIONS - WARNING: DO NOT DELETE OR MODIFY THIS LINE ///
|
|
30
|
+
{{#each functions}}
|
|
31
|
+
{{functionDefinition this}}
|
|
32
|
+
{{/each}}
|
|
33
|
+
}`, { noEscape: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const doomsdayTargetsTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.doomsdayTargetsTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("../handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.doomsdayTargetsTemplate = handlebars_1.default.compile(`// SPDX-License-Identifier: GPL-2.0
|
|
11
|
+
pragma solidity ^0.8.0;
|
|
12
|
+
|
|
13
|
+
import {BaseTargetFunctions} from "@chimera/BaseTargetFunctions.sol";
|
|
14
|
+
import {BeforeAfter} from "../BeforeAfter.sol";
|
|
15
|
+
import {Properties} from "../Properties.sol";
|
|
16
|
+
// Chimera deps
|
|
17
|
+
import {vm} from "@chimera/Hevm.sol";
|
|
18
|
+
|
|
19
|
+
// Helpers
|
|
20
|
+
import {Panic} from "@recon/Panic.sol";
|
|
21
|
+
|
|
22
|
+
abstract contract DoomsdayTargets is
|
|
23
|
+
BaseTargetFunctions,
|
|
24
|
+
Properties
|
|
25
|
+
{
|
|
26
|
+
/// Makes a handler have no side effects
|
|
27
|
+
/// The fuzzer will call this anyway, and because it reverts it will be removed from shrinking
|
|
28
|
+
/// Replace the "withGhosts" with "stateless" to make the code clean
|
|
29
|
+
modifier stateless() {
|
|
30
|
+
_;
|
|
31
|
+
revert("stateless");
|
|
32
|
+
}
|
|
33
|
+
}`, { noEscape: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const managersTargetsTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.managersTargetsTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("../handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.managersTargetsTemplate = handlebars_1.default.compile(`// SPDX-License-Identifier: GPL-2.0
|
|
11
|
+
pragma solidity ^0.8.0;
|
|
12
|
+
|
|
13
|
+
import {BaseTargetFunctions} from "@chimera/BaseTargetFunctions.sol";
|
|
14
|
+
import {BeforeAfter} from "../BeforeAfter.sol";
|
|
15
|
+
import {Properties} from "../Properties.sol";
|
|
16
|
+
import {vm} from "@chimera/Hevm.sol";
|
|
17
|
+
|
|
18
|
+
import {MockERC20} from "@recon/MockERC20.sol";
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
// Target functions that are effectively inherited from the Actor and AssetManagers
|
|
22
|
+
// Once properly standardized, managers will expose these by default
|
|
23
|
+
// Keeping them out makes your project more custom
|
|
24
|
+
abstract contract ManagersTargets is
|
|
25
|
+
BaseTargetFunctions,
|
|
26
|
+
Properties
|
|
27
|
+
{
|
|
28
|
+
// == ACTOR HANDLERS == //
|
|
29
|
+
|
|
30
|
+
/// @dev Start acting as another actor
|
|
31
|
+
function switchActor(uint256 entropy) public {
|
|
32
|
+
_switchActor(entropy);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/// @dev Starts using a new asset
|
|
37
|
+
function switch_asset(uint256 entropy) public {
|
|
38
|
+
_switchAsset(entropy);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// @dev Deploy a new token and add it to the list of assets, then set it as the current asset
|
|
42
|
+
function add_new_asset(uint8 decimals) public returns (address) {
|
|
43
|
+
address newAsset = _newAsset(decimals);
|
|
44
|
+
return newAsset;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// === GHOST UPDATING HANDLERS ===///
|
|
48
|
+
/// We updateGhosts cause you never know (e.g. donations)
|
|
49
|
+
/// If you don't want to track donations, remove the updateGhosts
|
|
50
|
+
|
|
51
|
+
/// @dev Approve to arbitrary address, uses Actor by default
|
|
52
|
+
/// NOTE: You're almost always better off setting approvals in Setup
|
|
53
|
+
function asset_approve(address to, uint128 amt) public updateGhosts asActor {
|
|
54
|
+
MockERC20(_getAsset()).approve(to, amt);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// @dev Mint to arbitrary address, uses owner by default, even though MockERC20 doesn't check
|
|
58
|
+
function asset_mint(address to, uint128 amt) public updateGhosts asAdmin {
|
|
59
|
+
MockERC20(_getAsset()).mint(to, amt);
|
|
60
|
+
}
|
|
61
|
+
}`, { noEscape: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const targetsTemplate: HandlebarsTemplateDelegate<any>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.targetsTemplate = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const handlebars_helpers_1 = require("../handlebars-helpers");
|
|
9
|
+
(0, handlebars_helpers_1.registerHelpers)(handlebars_1.default);
|
|
10
|
+
exports.targetsTemplate = handlebars_1.default.compile(`// SPDX-License-Identifier: GPL-2.0
|
|
11
|
+
pragma solidity ^0.8.0;
|
|
12
|
+
|
|
13
|
+
import {BaseTargetFunctions} from "@chimera/BaseTargetFunctions.sol";
|
|
14
|
+
import {BeforeAfter} from "../BeforeAfter.sol";
|
|
15
|
+
import {Properties} from "../Properties.sol";
|
|
16
|
+
// Chimera deps
|
|
17
|
+
import {vm} from "@chimera/Hevm.sol";
|
|
18
|
+
|
|
19
|
+
// Helpers
|
|
20
|
+
import {Panic} from "@recon/Panic.sol";
|
|
21
|
+
|
|
22
|
+
{{#if path}}import "{{path}}";{{/if}}
|
|
23
|
+
|
|
24
|
+
abstract contract {{pascal contractName}}Targets is
|
|
25
|
+
BaseTargetFunctions,
|
|
26
|
+
Properties
|
|
27
|
+
{
|
|
28
|
+
/// CUSTOM TARGET FUNCTIONS - Add your own target functions here ///
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/// AUTO GENERATED TARGET FUNCTIONS - WARNING: DO NOT DELETE OR MODIFY THIS LINE ///
|
|
32
|
+
{{#each functions}}
|
|
33
|
+
{{functionDefinition this}}
|
|
34
|
+
{{/each}}
|
|
35
|
+
}`, { noEscape: true });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare enum Actor {
|
|
2
|
+
ACTOR = "actor",
|
|
3
|
+
ADMIN = "admin"
|
|
4
|
+
}
|
|
5
|
+
export declare enum Mode {
|
|
6
|
+
NORMAL = "normal",
|
|
7
|
+
FAIL = "fail",
|
|
8
|
+
CATCH = "catch"
|
|
9
|
+
}
|
|
10
|
+
export type ParamDefinition = {
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
internalType: string;
|
|
14
|
+
components?: ParamDefinition[];
|
|
15
|
+
};
|
|
16
|
+
export type Abi = {
|
|
17
|
+
type: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
inputs: ParamDefinition[];
|
|
20
|
+
outputs: ParamDefinition[];
|
|
21
|
+
stateMutability?: string;
|
|
22
|
+
};
|
|
23
|
+
export type ContractMetadata = {
|
|
24
|
+
name: string;
|
|
25
|
+
jsonPath: string;
|
|
26
|
+
path: string;
|
|
27
|
+
abi: Abi[];
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
functionConfigs?: FunctionConfig[];
|
|
30
|
+
separated?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type FunctionConfig = {
|
|
33
|
+
signature: string;
|
|
34
|
+
actor: Actor;
|
|
35
|
+
mode: Mode;
|
|
36
|
+
};
|
|
37
|
+
export interface FunctionDefinitionParams {
|
|
38
|
+
contractName: string;
|
|
39
|
+
contractPath: string;
|
|
40
|
+
functionName: string;
|
|
41
|
+
abi: Abi;
|
|
42
|
+
actor: Actor;
|
|
43
|
+
mode: Mode;
|
|
44
|
+
separated?: boolean;
|
|
45
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mode = exports.Actor = void 0;
|
|
4
|
+
var Actor;
|
|
5
|
+
(function (Actor) {
|
|
6
|
+
Actor["ACTOR"] = "actor";
|
|
7
|
+
Actor["ADMIN"] = "admin";
|
|
8
|
+
})(Actor || (exports.Actor = Actor = {}));
|
|
9
|
+
var Mode;
|
|
10
|
+
(function (Mode) {
|
|
11
|
+
Mode["NORMAL"] = "normal";
|
|
12
|
+
Mode["FAIL"] = "fail";
|
|
13
|
+
Mode["CATCH"] = "catch";
|
|
14
|
+
})(Mode || (exports.Mode = Mode = {}));
|