mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Use deterministically generated script tests
Now that signing is deterministic, we can require exact correspondence between the automatically generated tests and the ones read from JSON. Do this, and update the tests to those deterministic versions. Note that some flag changes weren't correctly applied before.
This commit is contained in:
parent
7026cbd6db
commit
f67a9ce0dc
3 changed files with 65 additions and 76 deletions
|
|
@ -491,24 +491,18 @@ BOOST_AUTO_TEST_CASE(script_build)
|
|||
).Num(0).PushSig(keys.key1).PushSig(keys.key1));
|
||||
|
||||
|
||||
std::map<std::string, Array> tests_good;
|
||||
std::map<std::string, Array> tests_bad;
|
||||
std::set<std::string> tests_good;
|
||||
std::set<std::string> tests_bad;
|
||||
|
||||
{
|
||||
Array json_good = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid)));
|
||||
Array json_bad = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid)));
|
||||
|
||||
BOOST_FOREACH(Value& tv, json_good) {
|
||||
Array test = tv.get_array();
|
||||
if (test.size() >= 4) {
|
||||
tests_good[test[3].get_str()] = test;
|
||||
}
|
||||
tests_good.insert(write_string(Value(tv.get_array()), true));
|
||||
}
|
||||
BOOST_FOREACH(Value& tv, json_bad) {
|
||||
Array test = tv.get_array();
|
||||
if (test.size() >= 4) {
|
||||
tests_bad[test[3].get_str()] = test;
|
||||
}
|
||||
tests_bad.insert(write_string(Value(tv.get_array()), true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -517,27 +511,23 @@ BOOST_AUTO_TEST_CASE(script_build)
|
|||
|
||||
BOOST_FOREACH(TestBuilder& test, good) {
|
||||
test.Test(true);
|
||||
if (tests_good.count(test.GetComment()) == 0) {
|
||||
std::string str = write_string(Value(test.GetJSON()), true);
|
||||
#ifndef UPDATE_JSON_TESTS
|
||||
if (tests_good.count(str) == 0) {
|
||||
BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + test.GetComment());
|
||||
#endif
|
||||
strGood += write_string(Value(test.GetJSON()), true) + ",\n";
|
||||
} else {
|
||||
BOOST_CHECK_MESSAGE(ParseScript(tests_good[test.GetComment()][1].get_str()) == test.GetScriptPubKey(), "ScriptPubKey mismatch in auto script_valid test: " + test.GetComment());
|
||||
strGood += write_string(Value(tests_good[test.GetComment()]), true) + ",\n";
|
||||
}
|
||||
#endif
|
||||
strGood += str + ",\n";
|
||||
}
|
||||
BOOST_FOREACH(TestBuilder& test, bad) {
|
||||
test.Test(false);
|
||||
if (tests_bad.count(test.GetComment()) == 0) {
|
||||
std::string str = write_string(Value(test.GetJSON()), true);
|
||||
#ifndef UPDATE_JSON_TESTS
|
||||
if (tests_bad.count(str) == 0) {
|
||||
BOOST_CHECK_MESSAGE(false, "Missing auto script_invalid test: " + test.GetComment());
|
||||
#endif
|
||||
strBad += write_string(Value(test.GetJSON()), true) + ",\n";
|
||||
} else {
|
||||
BOOST_CHECK_MESSAGE(ParseScript(tests_bad[test.GetComment()][1].get_str()) == test.GetScriptPubKey(), "ScriptPubKey mismatch in auto script_invalid test: " + test.GetComment());
|
||||
strBad += write_string(Value(tests_bad[test.GetComment()]), true) + ",\n";
|
||||
}
|
||||
#endif
|
||||
strBad += str + ",\n";
|
||||
}
|
||||
|
||||
#ifdef UPDATE_JSON_TESTS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue