MCPcopy Create free account
hub / github.com/dharmaprotocol/dharmaOS / validateActionScriptTest

Method validateActionScriptTest

src/test-validator.js:91–216  ·  view source on GitHub ↗
(actionScriptTest)

Source from the content-addressed store, hash-verified

89 }
90
91 validateActionScriptTest(actionScriptTest) {
92 for (let [field, type] of Object.entries(
93 TOP_LEVEL_FIELDS_AND_TYPES
94 )) {
95 if (!(field in actionScriptTest)) {
96 throw new Error(
97 `Action script test "${actionScriptTest.name}" must contain a "${field}" field`
98 );
99 }
100 if (!TYPE_CHECKERS[type](actionScriptTest[field])) {
101 throw new Error(
102 `Action script test "${actionScriptTest.name}" field "${field}" must be of type "${type}"`
103 );
104 }
105 }
106 const { name, blockNumber, tests } = actionScriptTest;
107
108 const actionScriptOptions = this.actionScripts.filter(
109 (script) => script.name === name
110 );
111 if (actionScriptOptions.length === 0) {
112 throw new Error(
113 `Could not locate action script with name "${name}"`
114 );
115 }
116
117 const actionScript = actionScriptOptions[0];
118
119 for (let [testNumber, test] of Object.entries(tests)) {
120 if (!test || !("name" in test)) {
121 throw new Error(
122 `Action script test "${name}" test #${
123 parseInt(testNumber) + 1
124 } does not itself have a "name" field`
125 );
126 }
127 const testName = test.name;
128
129 for (let [field, type] of Object.entries(
130 TEST_LEVEL_FIELDS_AND_TYPES
131 )) {
132 if (!(field in test)) {
133 throw new Error(
134 `Action script test "${testName}" on "${name}" must contain a "${field}" field`
135 );
136 }
137 if (!TYPE_CHECKERS[type](test[field])) {
138 throw new Error(
139 `Action script test "${testName}" on "${name}" has a field "${field}" that is not of type "${type}"`
140 );
141 }
142 }
143
144 for (const [variableName, variableType] of Object.entries(
145 actionScript.variables
146 )) {
147 if (!(variableName in test.variables)) {
148 throw new Error(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected