From 2f6239da638ff7359961f7db52ca285e49953dbc Mon Sep 17 00:00:00 2001 From: barton26 Date: Tue, 28 Sep 2021 14:46:49 -0400 Subject: [PATCH 1/4] Add copyright header, clean up includes. Remove namespace declaration --- src/test/script_p2sh_tests.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp index 6c6b943e12..13f8d3af0c 100755 --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -1,16 +1,16 @@ -#include -#include -#include -#include -#include +// Copyright (c) 2012-2020 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include +#include -#include "main.h" -#include "policy/policy.h" -#include "script.h" -#include "validation.h" -#include "wallet/wallet.h" +#include -using namespace std; +#include // Test routines internal to script.cpp: extern uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType); @@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard) std::map > mapInputs; CBasicKeyStore keystore; CKey key[3]; - vector keys; + std::vector keys; for (int i = 0; i < 3; i++) { key[i].MakeNewKey(true); @@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard) oneOfEleven << OP_11 << OP_CHECKMULTISIG; txFrom.vout[5].scriptPubKey.SetDestination(oneOfEleven.GetID()); - mapInputs[txFrom.GetHash()] = make_pair(CTxIndex(), txFrom); + mapInputs[txFrom.GetHash()] = std::make_pair(CTxIndex(), txFrom); CTransaction txTo; txTo.vout.resize(1); From 38d1da3b6f52887780dd0d2f62829dd12015fd8f Mon Sep 17 00:00:00 2001 From: barton26 Date: Thu, 7 Oct 2021 20:03:34 -0400 Subject: [PATCH 2/4] Test for expected return values when calling functions returning a success code --- src/test/script_p2sh_tests.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp index 13f8d3af0c..c0a2e65673 100755 --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(sign) for (int i = 0; i < 4; i++) { key[i].MakeNewKey(true); - keystore.AddKey(key[i]); + BOOST_CHECK(keystore.AddKey(key[i])); } // 8 Scripts: checking all combinations of @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(sign) CScript evalScripts[4]; for (int i = 0; i < 4; i++) { - keystore.AddCScript(standardScripts[i]); + BOOST_CHECK(keystore.AddCScript(standardScripts[i])); evalScripts[i].SetDestination(standardScripts[i].GetID()); } @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(set) for (int i = 0; i < 4; i++) { key[i].MakeNewKey(true); - keystore.AddKey(key[i]); + BOOST_CHECK(keystore.AddKey(key[i])); keys.push_back(key[i]); } @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(set) for (int i = 0; i < 4; i++) { outer[i].SetDestination(inner[i].GetID()); - keystore.AddCScript(inner[i]); + BOOST_CHECK(keystore.AddCScript(inner[i])); } CTransaction txFrom; // Funding transaction: @@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard) for (int i = 0; i < 3; i++) { key[i].MakeNewKey(true); - keystore.AddKey(key[i]); + BOOST_CHECK(keystore.AddKey(key[i])); keys.push_back(key[i]); } @@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard) // First three are standard: CScript pay1; pay1.SetDestination(key[0].GetPubKey().GetID()); - keystore.AddCScript(pay1); + BOOST_CHECK(keystore.AddCScript(pay1)); CScript payScriptHash1; payScriptHash1.SetDestination(pay1.GetID()); CScript pay1of3; pay1of3.SetMultisig(1, keys); From 4aece52f8df3f559d8b39292a2dae14824eba723 Mon Sep 17 00:00:00 2001 From: barton26 Date: Thu, 7 Oct 2021 20:18:49 -0400 Subject: [PATCH 3/4] tests: Use std::vector API for construction of test data --- src/test/script_p2sh_tests.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp index c0a2e65673..575fb3ab05 100755 --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -201,14 +201,22 @@ BOOST_AUTO_TEST_CASE(is) BOOST_CHECK(p2sh.IsPayToScriptHash()); // Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes: - static const unsigned char direct[] = { OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL }; - BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToScriptHash()); - static const unsigned char pushdata1[] = { OP_HASH160, OP_PUSHDATA1, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL }; - BOOST_CHECK(!CScript(pushdata1, pushdata1+sizeof(pushdata1)).IsPayToScriptHash()); - static const unsigned char pushdata2[] = { OP_HASH160, OP_PUSHDATA2, 20,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL }; - BOOST_CHECK(!CScript(pushdata2, pushdata2+sizeof(pushdata2)).IsPayToScriptHash()); - static const unsigned char pushdata4[] = { OP_HASH160, OP_PUSHDATA4, 20,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL }; - BOOST_CHECK(!CScript(pushdata4, pushdata4+sizeof(pushdata4)).IsPayToScriptHash()); + std::vector direct = {OP_HASH160, 20}; + direct.insert(direct.end(), 20, 0); + direct.push_back(OP_EQUAL); + BOOST_CHECK(CScript(direct.begin(), direct.end()).IsPayToScriptHash()); + std::vector pushdata1 = {OP_HASH160, OP_PUSHDATA1, 20}; + pushdata1.insert(pushdata1.end(), 20, 0); + pushdata1.push_back(OP_EQUAL); + BOOST_CHECK(!CScript(pushdata1.begin(), pushdata1.end()).IsPayToScriptHash()); + std::vector pushdata2 = {OP_HASH160, 20, 0}; + pushdata2.insert(pushdata2.end(), 20, 0); + pushdata2.push_back(OP_EQUAL); + BOOST_CHECK(!CScript(pushdata2.begin(), pushdata2.end()).IsPayToScriptHash()); + std::vector pushdata4 = {OP_HASH160, 20, 0, 0, 0}; + pushdata4.insert(pushdata4.end(), 20, 0); + pushdata4.push_back(OP_EQUAL); + BOOST_CHECK(!CScript(pushdata4.begin(), pushdata4.end()).IsPayToScriptHash()); CScript not_p2sh; BOOST_CHECK(!not_p2sh.IsPayToScriptHash()); From 9acda2c627ec96a27807fc128ba8d5e52b23fdf2 Mon Sep 17 00:00:00 2001 From: barton26 Date: Thu, 7 Oct 2021 21:59:18 -0400 Subject: [PATCH 4/4] test: fix script_p2sh_tests OP_PUSHBACK2/4 missing --- src/test/script_p2sh_tests.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp index 575fb3ab05..132543f89e 100755 --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -200,20 +200,21 @@ BOOST_AUTO_TEST_CASE(is) p2sh << OP_HASH160 << dummy << OP_EQUAL; BOOST_CHECK(p2sh.IsPayToScriptHash()); - // Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes: std::vector direct = {OP_HASH160, 20}; direct.insert(direct.end(), 20, 0); direct.push_back(OP_EQUAL); BOOST_CHECK(CScript(direct.begin(), direct.end()).IsPayToScriptHash()); + + // Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes: std::vector pushdata1 = {OP_HASH160, OP_PUSHDATA1, 20}; pushdata1.insert(pushdata1.end(), 20, 0); pushdata1.push_back(OP_EQUAL); BOOST_CHECK(!CScript(pushdata1.begin(), pushdata1.end()).IsPayToScriptHash()); - std::vector pushdata2 = {OP_HASH160, 20, 0}; + std::vector pushdata2 = {OP_HASH160, OP_PUSHDATA2, 20, 0}; pushdata2.insert(pushdata2.end(), 20, 0); pushdata2.push_back(OP_EQUAL); BOOST_CHECK(!CScript(pushdata2.begin(), pushdata2.end()).IsPayToScriptHash()); - std::vector pushdata4 = {OP_HASH160, 20, 0, 0, 0}; + std::vector pushdata4 = {OP_HASH160, OP_PUSHDATA4, 20, 0, 0, 0}; pushdata4.insert(pushdata4.end(), 20, 0); pushdata4.push_back(OP_EQUAL); BOOST_CHECK(!CScript(pushdata4.begin(), pushdata4.end()).IsPayToScriptHash());