| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE(script_assets_test) |
| 150 | { |
| 151 | // See src/test/fuzz/script_assets_test_minimizer.cpp for information on how to generate |
| 152 | // the script_assets_test.json file used by this test. |
| 153 | SignatureCache signature_cache{DEFAULT_SIGNATURE_CACHE_BYTES}; |
| 154 | |
| 155 | const char* dir = std::getenv("DIR_UNIT_TEST_DATA"); |
| 156 | BOOST_WARN_MESSAGE(dir != nullptr, "Variable DIR_UNIT_TEST_DATA unset, skipping script_assets_test"); |
| 157 | if (dir == nullptr) return; |
| 158 | auto path = fs::path(dir) / "script_assets_test.json"; |
| 159 | bool exists = fs::exists(path); |
| 160 | BOOST_WARN_MESSAGE(exists, "File $DIR_UNIT_TEST_DATA/script_assets_test.json not found, skipping script_assets_test"); |
| 161 | if (!exists) return; |
| 162 | std::ifstream file{path.std_path()}; |
| 163 | BOOST_CHECK(file.is_open()); |
| 164 | file.seekg(0, std::ios::end); |
| 165 | size_t length = file.tellg(); |
| 166 | file.seekg(0, std::ios::beg); |
| 167 | std::string data(length, '\0'); |
| 168 | file.read(data.data(), data.size()); |
| 169 | UniValue tests = read_json(data); |
| 170 | BOOST_CHECK(tests.isArray()); |
| 171 | BOOST_CHECK(tests.size() > 0); |
| 172 | |
| 173 | for (size_t i = 0; i < tests.size(); i++) { |
| 174 | AssetTest(tests[i], signature_cache); |
| 175 | } |
| 176 | file.close(); |
| 177 | } |
| 178 | |
| 179 | BOOST_AUTO_TEST_SUITE_END() |