Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests] Resurrect feature_block and kill the p2p comparison test framework #2360

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b2410ae
[BUG] Fix assertion in error in assert_debug_log
random-zebra May 2, 2021
bd6e591
[Refactoring] remove SaplingActive check in GUI/RPC
random-zebra May 3, 2021
9d552f9
[Refactor][Tests] Do not change chain when not needed
random-zebra May 3, 2021
f5f72ca
[Trivial] Update some state logs (tx oversize and inputs missing/spent)
random-zebra May 2, 2021
0b670c8
[BUG] Properly recompute coinbase and sapling root hash in CreateBlock
random-zebra May 3, 2021
44a1c44
[Refactor] Option to mine mempool txes in TestChainSetup::CreateBlock
random-zebra May 3, 2021
4cf7222
[Tests] Refactor wallet_sapling_transactions_validations_tests
random-zebra May 3, 2021
93fcc2e
[Params] Fix regtest coinbase - mine it with lower diff
random-zebra May 2, 2021
d0777a7
[Refactoring] Add fPowNoRetargeting consensus param + fix regtest diff
random-zebra Apr 30, 2021
810a880
[Tests] Update PIVX specific constants bits/block-size/block-version
random-zebra May 2, 2021
b19bee9
[Refactoring][BUG] Never change chain-params after setup in unit tests
random-zebra May 3, 2021
0f0c97c
[BUG] Fix block with invalid PoW in zerocoin_rejection_tests
random-zebra May 5, 2021
030517b
[Refactoring] pass next block height to IncrementExtraNonce
random-zebra May 5, 2021
77645bf
[BUG][Tests] Add on_getblocks to P2PDataStore interface
random-zebra May 3, 2021
3633e42
[Tests] Fix and resurrect feature_block.py
random-zebra May 2, 2021
fcda6cc
[QA][Cleanup] Retire the Comparison Test Framework
random-zebra May 3, 2021
48e5d54
[Tests][Refactoring] Remove 'magic bytes' in p2p_invalid_* tests
random-zebra May 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 40 additions & 52 deletions src/test/librust/sapling_rpc_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_validateaddress)

BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
{
SelectParams(CBaseChainParams::TESTNET);

{
LOCK(pwalletMain->cs_wallet);
pwalletMain->SetMinVersion(FEATURE_SAPLING);
Expand All @@ -96,25 +94,25 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_getbalance)
BOOST_CHECK_THROW(CallRPC("getshieldbalance too many args"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("getshieldbalance invalidaddress"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("getshieldbalance tmC6YZnCUhm19dEXxh3Jb7srdBJxDawaCab"), std::runtime_error);
BOOST_CHECK_NO_THROW(CallRPC("getshieldbalance ptestsapling1h0w73csah2aq0a32h42kr7tq4htlt5wfn4ejxfnm56f6ehjvek7k4e244g6v8v3pgylmz5ea8jh"));
BOOST_CHECK_THROW(CallRPC("getshieldbalance ptestsapling1h0w73csah2aq0a32h42kr7tq4htlt5wfn4ejxfnm56f6ehjvek7k4e244g6v8v3pgylmz5ea8jh -1"), std::runtime_error);
BOOST_CHECK_NO_THROW(CallRPC("getshieldbalance ptestsapling1nrn6exksuqtpld9gu6fwdz4hwg54h2x37gutdds89pfyg6mtjf63km45a8eare5qla45cj75vs8 0"));
BOOST_CHECK_NO_THROW(CallRPC("getshieldbalance ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej"));
BOOST_CHECK_THROW(CallRPC("getshieldbalance ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej -1"), std::runtime_error);
BOOST_CHECK_NO_THROW(CallRPC("getshieldbalance ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej 0"));
BOOST_CHECK_THROW(CallRPC("getshieldbalance tnRZ8bPq2pff3xBWhTJhNkVUkm2uhzksDeW5PvEa7aFKGT9Qi3YgTALZfjaY4jU3HLVKBtHdSXxoPoLA3naMPcHBcY88FcF 1"), std::runtime_error);
BOOST_CHECK_NO_THROW(CallRPC("getshieldbalance *"));
BOOST_CHECK_NO_THROW(CallRPC("getshieldbalance * 6"));
BOOST_CHECK_THROW(CallRPC("getshieldbalance * -1"), std::runtime_error);

BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress too many args"), std::runtime_error);
// negative minconf not allowed
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress yBYhwgzufrZ6F5VVuK9nEChENArq934mqC -1"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ -1"), std::runtime_error);
// invalid zaddr, taddr not allowed
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress yBYhwgzufrZ6F5VVuK9nEChENArq934mqC 0"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ 0"), std::runtime_error);
// don't have the spending key
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress ptestsapling1nrn6exksuqtpld9gu6fwdz4hwg54h2x37gutdds89pfyg6mtjf63km45a8eare5qla45cj75vs8 1"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("listreceivedbyshieldaddress ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej 1"), std::runtime_error);
}

BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importkey_paymentaddress) {
SelectParams(CBaseChainParams::MAIN);
BOOST_AUTO_TEST_CASE(rpc_wallet_sapling_importkey_paymentaddress)
{
{
LOCK(pwalletMain->cs_wallet);
pwalletMain->SetMinVersion(FEATURE_SAPLING);
Expand Down Expand Up @@ -234,25 +232,23 @@ void CheckHaveAddr(const libzcash::PaymentAddress& addr) {
BOOST_CHECK(pwalletMain->HaveSpendingKeyForPaymentAddress(*addr_of_type));
}

BOOST_AUTO_TEST_CASE(rpc_wallet_getnewshieldaddress) {
UniValue addr;
BOOST_AUTO_TEST_CASE(rpc_wallet_getnewshieldaddress)
{
{
LOCK(pwalletMain->cs_wallet);
pwalletMain->SetMinVersion(FEATURE_SAPLING);
pwalletMain->SetupSPKM(false);
}

// No parameter defaults to sapling address
addr = CallRPC("getnewshieldaddress");
UniValue addr = CallRPC("getnewshieldaddress");
CheckHaveAddr(KeyIO::DecodePaymentAddress(addr.get_str()));
// Too many arguments will throw with the help
BOOST_CHECK_THROW(CallRPC("getnewshieldaddress many args"), std::runtime_error);
}

BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)
{
SelectParams(CBaseChainParams::TESTNET);

{
LOCK(pwalletMain->cs_wallet);
pwalletMain->SetMinVersion(FEATURE_SAPLING);
Expand All @@ -265,41 +261,40 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)

// bad from address
BOOST_CHECK_THROW(CallRPC("shieldsendmany "
"INVALIDyBYhwgzufrZ6F5VVuK9nEChENArq934mqC []"), std::runtime_error);
"INVALIDDMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ []"), std::runtime_error);
// empty amounts
BOOST_CHECK_THROW(CallRPC("shieldsendmany "
"yBYhwgzufrZ6F5VVuK9nEChENArq934mqC []"), std::runtime_error);
"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ []"), std::runtime_error);

// don't have the spending key for this address
BOOST_CHECK_THROW(CallRPC("shieldsendmany "
"ptestsapling1wpurflqllgkcs48m46yu9ktlfe3ahndely20dpaanqq3lw9l5xw7yfehst68yclvlpz7x8cltxe"
"UkJ1oSfbhTJhm72WiZizvkZz5aH1 []"), std::runtime_error);
"ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej []"), std::runtime_error);

// duplicate address
BOOST_CHECK_THROW(CallRPC("shieldsendmany "
"yBYhwgzufrZ6F5VVuK9nEChENArq934mqC "
"[{\"address\":\"yAJ4bGeDFcEtx24kbr413fBLpWQcdR5F2z\", \"amount\":50.0},"
" {\"address\":\"yAJ4bGeDFcEtx24kbr413fBLpWQcdR5F2z\", \"amount\":12.0} ]"
"DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
"[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0},"
" {\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":12.0} ]"
), std::runtime_error);

// invalid fee amount, cannot be negative
BOOST_CHECK_THROW(CallRPC("shieldsendmany "
"yBYhwgzufrZ6F5VVuK9nEChENArq934mqC "
"[{\"address\":\"yAJ4bGeDFcEtx24kbr413fBLpWQcdR5F2z\", \"amount\":50.0}] "
"DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
"[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0}] "
"1 -0.0001"
), std::runtime_error);

// invalid fee amount, bigger than MAX_MONEY
BOOST_CHECK_THROW(CallRPC("shieldsendmany "
"yBYhwgzufrZ6F5VVuK9nEChENArq934mqC "
"[{\"address\":\"yAJ4bGeDFcEtx24kbr413fBLpWQcdR5F2z\", \"amount\":50.0}] "
"DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
"[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0}] "
"1 21000001"
), std::runtime_error);

// fee amount is bigger than sum of outputs
BOOST_CHECK_THROW(CallRPC("shieldsendmany "
"yBYhwgzufrZ6F5VVuK9nEChENArq934mqC "
"[{\"address\":\"yAJ4bGeDFcEtx24kbr413fBLpWQcdR5F2z\", \"amount\":50.0}] "
"DDTBEPEaub5sk31mUifiv5nHGXtHGnuAJc "
"[{\"address\":\"DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ\", \"amount\":50.0}] "
"1 50.00000001"
), std::runtime_error);

Expand All @@ -309,18 +304,18 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_parameters)
std::string badmemo(v.begin(), v.end());
auto pa = pwalletMain->GenerateNewSaplingZKey();
std::string zaddr1 = KeyIO::EncodePaymentAddress(pa);
BOOST_CHECK_THROW(CallRPC(std::string("shieldsendmany yBYhwgzufrZ6F5VVuK9nEChENArq934mqC ")
BOOST_CHECK_THROW(CallRPC(std::string("shieldsendmany DMKU6mc52un1MThGCsnNwAtEvncaTdAuaZ ")
+ "[{\"address\":\"" + zaddr1 + "\", \"amount\":123.456}]"), std::runtime_error);
}

// TODO: test private methods
BOOST_AUTO_TEST_CASE(saplingOperationTests) {
RegtestActivateSapling();
auto consensusParams = Params().GetConsensus();

LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->SetupSPKM(false);
BOOST_AUTO_TEST_CASE(saplingOperationTests)
{
{
LOCK2(cs_main, pwalletMain->cs_wallet);
random-zebra marked this conversation as resolved.
Show resolved Hide resolved
pwalletMain->SetupSPKM(false);
}

auto consensusParams = Params().GetConsensus();
UniValue retValue;

// add keys manually
Expand Down Expand Up @@ -388,17 +383,15 @@ BOOST_AUTO_TEST_CASE(saplingOperationTests) {
const std::string& errStr = res.getError();
BOOST_CHECK(errStr.find("too big") != std::string::npos);
}
RegtestDeactivateSapling();
}


BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
{
SelectParams(CBaseChainParams::REGTEST);
RegtestActivateSapling();

LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->SetupSPKM(false);
{
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->SetupSPKM(false);
}

UniValue retValue;

Expand Down Expand Up @@ -477,9 +470,6 @@ BOOST_AUTO_TEST_CASE(rpc_shieldsendmany_taddr_to_sapling)
// Tear down
chainActive.SetTip(nullptr);
mapBlockIndex.erase(blockHash);

// Revert to default
RegtestDeactivateSapling();
}

BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)
Expand Down Expand Up @@ -546,8 +536,6 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_encrypted_wallet_sapzkeys)

BOOST_AUTO_TEST_CASE(rpc_listshieldunspent_parameters)
{
SelectParams(CBaseChainParams::TESTNET);

{
LOCK(pwalletMain->cs_wallet);
pwalletMain->SetupSPKM(false);
Expand All @@ -568,19 +556,19 @@ BOOST_AUTO_TEST_CASE(rpc_listshieldunspent_parameters)
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 9999999999"), std::runtime_error);

// must be an array of addresses
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 false ptestsapling1wpurflqllgkcs48m46yu9ktlfe3ahndely20dpaanqq3lw9l5xw7yfehst68yclvlpz7x8cltxe"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 false ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej"), std::runtime_error);

// address must be string
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 false [123456]"), std::runtime_error);

// no spending key
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 false [\"ptestsapling1wpurflqllgkcs48m46yu9ktlfe3ahndely20dpaanqq3lw9l5xw7yfehst68yclvlpz7x8cltxe\"]"), std::runtime_error);
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 false [\"ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej\"]"), std::runtime_error);

// allow watch only
BOOST_CHECK_NO_THROW(CallRPC("listshieldunspent 1 999 true [\"ptestsapling1wpurflqllgkcs48m46yu9ktlfe3ahndely20dpaanqq3lw9l5xw7yfehst68yclvlpz7x8cltxe\"]"));
BOOST_CHECK_NO_THROW(CallRPC("listshieldunspent 1 999 true [\"ps1u87kylcmn28yclnx2uy0psnvuhs2xn608ukm6n2nshrpg2nzyu3n62ls8j77m9cgp40dx40evej\"]"));

// wrong network, mainnet instead of testnet
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 true [\"ps1qenk9kapr0crx7lmdl4yclx78spc36wh7d5hm9hglp85f43k9dupyf0c5836h42wq2ejv0ef2v3\"]"), std::runtime_error);
// wrong network, testnet/regtest instead of mainnet
BOOST_CHECK_THROW(CallRPC("listshieldunspent 1 999 true [\"ptestsapling1wpurflqllgkcs48m46yu9ktlfe3ahndely20dpaanqq3lw9l5xw7yfehst68yclvlpz7x8cltxe\"]"), std::runtime_error);

// create shielded address so we have the spending key
BOOST_CHECK_NO_THROW(retValue = CallRPC("getnewshieldaddress"));
Expand Down
10 changes: 4 additions & 6 deletions src/test/script_P2CS_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ BOOST_AUTO_TEST_CASE(extract_cold_staking_destination_keys)

static CScript GetNewP2CS(CKey& stakerKey, CKey& ownerKey, bool fLastOutFree)
{
stakerKey = DecodeSecret("91yo52JPHDVUG3jXWLKGyzEdjn1a9nbnurLdmQEf2UzbgzkTc2c");
ownerKey = DecodeSecret("92KgNFNfmVVJRQuzssETc7NhwufGuHsLvPQxW9Nwmxs7PB4ByWB");
stakerKey = DecodeSecret("YNdsth3BsW53DYmCiR12SofWSAt2utXQUSGoin3PekVQCMbzfS7E");
ownerKey = DecodeSecret("YUo8oW3y8cUQdQxQxCdnUJ4Ww5H7nHBEMwD2bNDpBbuLM59t4rvd");
return fLastOutFree ? GetScriptForStakeDelegationLOF(stakerKey.GetPubKey().GetID(), ownerKey.GetPubKey().GetID())
: GetScriptForStakeDelegation(stakerKey.GetPubKey().GetID(), ownerKey.GetPubKey().GetID());
}
Expand Down Expand Up @@ -124,7 +124,6 @@ static bool CheckP2CSScript(const CScript& scriptSig, const CScript& scriptPubKe

BOOST_AUTO_TEST_CASE(coldstake_lof_script)
{
SelectParams(CBaseChainParams::REGTEST);
CScript scriptP2CS;
CKey stakerKey, ownerKey;

Expand All @@ -150,7 +149,7 @@ BOOST_AUTO_TEST_CASE(coldstake_lof_script)
SignColdStake(tx, 0, scriptP2CS, stakerKey, true);
BOOST_CHECK(CheckP2CSScript(tx.vin[0].scriptSig, scriptP2CS, tx, err));

const CKey& dummyKey = DecodeSecret("91t7cwPGevo885Uccg87nVjzUxKhXta9JprHM3R21PQkBFMFg2i");
const CKey& dummyKey = DecodeSecret("YNdsth3BsW53DYmCiR12SofWSAt2utXQUSGoin3PekVQCMbzfS7E");
const CKeyID& dummyKeyID = dummyKey.GetPubKey().GetID();
const CScript& dummyP2PKH = GetDummyP2PKH(dummyKeyID);

Expand Down Expand Up @@ -201,7 +200,6 @@ BOOST_AUTO_TEST_CASE(coldstake_lof_script)

BOOST_AUTO_TEST_CASE(coldstake_script)
{
SelectParams(CBaseChainParams::REGTEST);
CScript scriptP2CS;
CKey stakerKey, ownerKey;

Expand All @@ -227,7 +225,7 @@ BOOST_AUTO_TEST_CASE(coldstake_script)
SignColdStake(tx, 0, scriptP2CS, stakerKey, true);
BOOST_CHECK(CheckP2CSScript(tx.vin[0].scriptSig, scriptP2CS, tx, err));

const CKey& dummyKey = DecodeSecret("91t7cwPGevo885Uccg87nVjzUxKhXta9JprHM3R21PQkBFMFg2i");
const CKey& dummyKey = DecodeSecret("YNdsth3BsW53DYmCiR12SofWSAt2utXQUSGoin3PekVQCMbzfS7E");
const CKeyID& dummyKeyID = dummyKey.GetPubKey().GetID();
const CScript& dummyP2PKH = GetDummyP2PKH(dummyKeyID);

Expand Down
21 changes: 4 additions & 17 deletions src/test/validation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

BOOST_FIXTURE_TEST_SUITE(validation_tests, TestingSetup)

void test_simple_sapling_invalidity(CMutableTransaction& tx)
BOOST_AUTO_TEST_CASE(test_simple_shielded_invalid)
{
CMutableTransaction tx;
tx.nVersion = CTransaction::TxVersion::SAPLING;
CAmount nDummyValueOut;
{
CMutableTransaction newTx(tx);
Expand Down Expand Up @@ -91,22 +93,6 @@ void test_simple_sapling_invalidity(CMutableTransaction& tx)
}
}

BOOST_AUTO_TEST_CASE(test_simple_shielded_invalid)
{
// Switch to regtest parameters so we can activate Sapling
SelectParams(CBaseChainParams::REGTEST);

CMutableTransaction mtx;
mtx.nVersion = CTransaction::TxVersion::SAPLING;

UpdateNetworkUpgradeParameters(Consensus::UPGRADE_V5_0, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
test_simple_sapling_invalidity(mtx);
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_V5_0, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT);

// Switch back to mainnet parameters as originally selected in test fixture
SelectParams(CBaseChainParams::MAIN);
}

void CheckBlockZcRejection(const std::shared_ptr<CBlock>& pblock, CMutableTransaction& mtx)
{
pblock->vtx.emplace_back(MakeTransactionRef(mtx));
Expand All @@ -129,6 +115,7 @@ void CheckMempoolZcRejection(CMutableTransaction& mtx)

BOOST_AUTO_TEST_CASE(zerocoin_rejection_tests)
{
// !TODO: fix me
SelectParams(CBaseChainParams::REGTEST);
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_V5_0, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
const CChainParams& chainparams = Params();
Expand Down