diff --git a/src/nameclaim.cpp b/src/nameclaim.cpp index d1aa3327e..ebb223d72 100644 --- a/src/nameclaim.cpp +++ b/src/nameclaim.cpp @@ -28,18 +28,22 @@ uint32_t vch_to_uint32_t(std::vector& vchN) return n; } -CScript ClaimNameScript(std::string name, std::string value) +CScript ClaimNameScript(std::string name, std::string value, bool fakeSuffix) { std::vector vchName(name.begin(), name.end()); std::vector vchValue(value.begin(), value.end()); - return CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP << OP_TRUE; + auto ret = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP; + if (fakeSuffix) ret.push_back(OP_TRUE); + return ret; } -CScript SupportClaimScript(std::string name, uint160 claimId) +CScript SupportClaimScript(std::string name, uint160 claimId, bool fakeSuffix) { std::vector vchName(name.begin(), name.end()); std::vector vchClaimId(claimId.begin(), claimId.end()); - return CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_DROP << OP_TRUE; + auto ret = CScript() << OP_SUPPORT_CLAIM << vchName << vchClaimId << OP_2DROP << OP_DROP; + if (fakeSuffix) ret.push_back(OP_TRUE); + return ret; } CScript UpdateClaimScript(std::string name, uint160 claimId, std::string value) diff --git a/src/nameclaim.h b/src/nameclaim.h index 0d9ff2775..591844327 100644 --- a/src/nameclaim.h +++ b/src/nameclaim.h @@ -25,8 +25,8 @@ // Scripts exceeding this size are rejected in CheckTransaction in main.cpp #define MAX_CLAIM_NAME_SIZE 255 -CScript ClaimNameScript(std::string name, std::string value); -CScript SupportClaimScript(std::string name, uint160 claimId); +CScript ClaimNameScript(std::string name, std::string value, bool fakeSuffix=true); +CScript SupportClaimScript(std::string name, uint160 claimId, bool fakeSuffix=true); CScript UpdateClaimScript(std::string name, uint160 claimId, std::string value); bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams); bool DecodeClaimScript(const CScript& scriptIn, int& op, std::vector >& vvchParams, CScript::const_iterator& pc); diff --git a/src/wallet/test/claim_rpc_tests.cpp b/src/wallet/test/claim_rpc_tests.cpp index be29f3da9..4694fab1e 100644 --- a/src/wallet/test/claim_rpc_tests.cpp +++ b/src/wallet/test/claim_rpc_tests.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include #include @@ -275,4 +277,81 @@ BOOST_AUTO_TEST_CASE(claim_op_runthrough_bech32) AddClaimSupportThenRemove(); } +std::vector SpendableCoins() { + rpcfn_type rpc_method = tableRPC["listunspent"]->actor; + JSONRPCRequest req; + req.URI = "/wallet/tester_wallet"; + req.params = UniValue(UniValue::VARR); + UniValue unspents = rpc_method(req); + std::vector ret; + for (uint32_t i = 0; i < unspents.size(); ++i) + ret.emplace_back(uint256S(unspents[i]["txid"].get_str()), unspents[i]["vout"].get_int()); + return ret; +} + +CTxDestination NewAddress(OutputType t) { + rpcfn_type rpc_method = tableRPC["getnewaddress"]->actor; + JSONRPCRequest req; + req.URI = "/wallet/tester_wallet"; + req.params = UniValue(UniValue::VARR); + req.params.push_back(""); + req.params.push_back(FormatOutputType(t)); + UniValue address = rpc_method(req); + return DecodeDestination(address.get_str()); +} + +std::string SignRawTransaction(const std::string& tx) { + rpcfn_type rpc_method = tableRPC["signrawtransactionwithwallet"]->actor; + JSONRPCRequest req; + req.URI = "/wallet/tester_wallet"; + req.params = UniValue(UniValue::VARR); + req.params.push_back(tx); + UniValue results = rpc_method(req); + BOOST_CHECK(results["complete"].get_bool()); + BOOST_CHECK(!results.exists("errors")); + return results["hex"].get_str(); +} + +std::string SendRawTransaction(const std::string& tx) { + rpcfn_type rpc_method = tableRPC["sendrawtransaction"]->actor; + JSONRPCRequest req; + req.URI = "/wallet/tester_wallet"; + req.params = UniValue(UniValue::VARR); + req.params.push_back(tx); + req.params.push_back(UniValue(true)); // allow high fees + UniValue results = rpc_method(req); + return results.get_str(); +} + + +BOOST_AUTO_TEST_CASE(can_sign_all_addr) +{ + generateBlock(110); + BOOST_CHECK_EQUAL(AvailableBalance(), 10.0); + auto coins = SpendableCoins(); + + std::vector txids; + for (std::size_t i = 0; i < 3; ++i) { + CMutableTransaction rawTx; + CTxIn in(coins[i], CScript(), 0); + rawTx.vin.push_back(in); + auto destination = NewAddress(OutputType(i)); + CScript scriptPubKey = ClaimNameScript("name" + std::to_string(i), "value", false) + + GetScriptForDestination(destination); + CTxOut out(100000, scriptPubKey); + rawTx.vout.push_back(out); + auto hex = EncodeHexTx(rawTx); + hex = SignRawTransaction(hex); + txids.push_back(SendRawTransaction(hex)); + } + generateBlock(1); + auto looked = LookupAllNames().get_array(); + + for (std::size_t i = 0; i < 3; ++i) { + BOOST_CHECK_EQUAL(looked[i]["name"].get_str(), "name" + std::to_string(i)); + BOOST_CHECK_EQUAL(looked[i]["value"].get_str(), HexStr(std::string("value"))); + BOOST_CHECK_EQUAL(looked[i]["txid"].get_str(), txids[i]); + } +} + BOOST_AUTO_TEST_SUITE_END()