Skip to content

Commit

Permalink
Merge pull request #149 from commerceblock/mswhitelist
Browse files Browse the repository at this point in the history
Minor changes to onboard tests and a certain key or script id safety check
  • Loading branch information
lawlawlaw authored Jun 25, 2019
2 parents 6957f9d + deb75c5 commit 65fb702
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 20 deletions.
21 changes: 18 additions & 3 deletions qa/rpc-tests/onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,15 @@ def run_test (self):
assert((balance_1-balance_2) == 0)

node1addr=self.nodes[1].getnewaddress()
iswl=self.nodes[0].querywhitelist(node1addr)

try:
iswl=self.nodes[0].querywhitelist(node1addr)
except JSONRPCException as e:
print(e.error['message'])
assert(False)
assert(iswl)


keypool=100
nwhitelisted=keypool

Expand Down Expand Up @@ -298,7 +304,11 @@ def run_test (self):
nlines4=self.linecount(wl1file_4)
assert_equal(nlines3+1, nlines4)

iswl=self.nodes[1].querywhitelist(multiAddress2['address'])
try:
iswl=self.nodes[1].querywhitelist(multiAddress2['address'])
except JSONRPCException as e:
print(e.error['message'])
assert(False)
assert(iswl)

multiAddress1=self.nodes[1].createmultisig(2,[clientAddress1['pubkey'],clientAddress2['pubkey'],clientAddress3['pubkey']])
Expand All @@ -316,7 +326,12 @@ def run_test (self):
nlines1=self.linecount(wl1file)
nlines2=self.linecount(wl1file_2)
assert_equal(nlines1+1,nlines2)
iswl=self.nodes[1].querywhitelist(multiAddress1['address'])

try:
iswl=self.nodes[1].querywhitelist(multiAddress1['address'])
except JSONRPCException as e:
print(e.error['message'])
assert(False)
assert(iswl)

if(clientAddress1['pubkey'] == clientAddress1['derivedpubkey']):
Expand Down
38 changes: 32 additions & 6 deletions qa/rpc-tests/onboardmanual.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,55 @@ def run_test (self):
onboardAddress2=self.nodes[1].validateaddress(self.nodes[1].getnewaddress())
onboardAddress3=self.nodes[1].validateaddress(self.nodes[1].getnewaddress())
untweakedPubkeys=[onboardAddress1['derivedpubkey'],onboardAddress2['derivedpubkey'],onboardAddress3['derivedpubkey']]
userOnboardPubKey=self.nodes[1].createkycfile(kycfile, [{"address":onboardAddress1['address'],"pubkey":onboardAddress1['derivedpubkey']},{"address":onboardAddress2['address'],"pubkey":onboardAddress2['derivedpubkey']}], [{"nmultisig":2,"pubkeys":untweakedPubkeys}]);

try:
userOnboardPubKey=self.nodes[1].createkycfile(kycfile, [{"address":onboardAddress1['address'],"pubkey":onboardAddress1['derivedpubkey']},{"address":onboardAddress2['address'],"pubkey":onboardAddress2['derivedpubkey']}], [{"nmultisig":2,"pubkeys":untweakedPubkeys}]);
except JSONRPCException as e:
print(e.error['message'])
assert(False)

self.nodes[0].generate(101)
self.sync_all()

balance_1=self.nodes[0].getwalletinfo()["balance"]["WHITELIST"]
self.nodes[0].onboarduser(kycfile)
try:
self.nodes[0].onboarduser(kycfile)
except JSONRPCException as e:
print(e.error['message'])
assert(False)

os.remove(kycfile)

time.sleep(5)
self.nodes[0].generate(101)
self.sync_all()
time.sleep(1)

balance_2=self.nodes[0].getwalletinfo()["balance"]["WHITELIST"]
#Make sure the onboard transaction fee was zero
assert((balance_1-balance_2) == 0)

node1addr=self.nodes[1].getnewaddress()
iswl=self.nodes[0].querywhitelist(onboardAddress1['address'])
try:
iswl=self.nodes[0].querywhitelist(onboardAddress1['address'])
except JSONRPCException as e:
print(e.error['message'])
assert(False)
assert(iswl)

try:
iswl=self.nodes[0].querywhitelist(onboardAddress2['address'])
except JSONRPCException as e:
print(e.error['message'])
assert(False)
assert(iswl)

multiAdr=self.nodes[1].createmultisig(2,[onboardAddress1['pubkey'],onboardAddress2['pubkey'],onboardAddress3['pubkey']])
iswl2=self.nodes[0].querywhitelist(multiAdr['address'])
try:
iswl2=self.nodes[0].querywhitelist(multiAdr['address'])
except JSONRPCException as e:
print(e.error['message'])
assert(False)
assert(iswl2)

return

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion src/policy/kycfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void CKYCFile::parseMultisig(const std::vector<std::string> vstr, const std::str
//Will throw an error if address is not a valid derived address.
CTxDestination multiKeyId;
multiKeyId = address.Get();
if (!boost::get<CNoDestination>(&multiKeyId)){
if (!(multiKeyId.which() == ((CTxDestination)CNoDestination()).which())){
if(!Consensus::CheckValidTweakedAddress(multiKeyId, pubKeys, nMultisig)){
_decryptedStream << line << ": invalid key tweaking\n";
return;
Expand Down
4 changes: 2 additions & 2 deletions src/policy/whitelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void CWhiteList::add_derived(const CBitcoinAddress& address, const CPubKey& pub
//Will throw an error if address is not a valid derived address.
CTxDestination keyId;
keyId = address.Get();
if (boost::get<CNoDestination>(&keyId))
if (keyId.which() == ((CTxDestination)CNoDestination()).which())
throw std::invalid_argument(std::string(std::string(__func__) +
": invalid key id"));

Expand Down Expand Up @@ -181,7 +181,7 @@ void CWhiteList::add_multisig_whitelist(const CBitcoinAddress& address, const st
//Will throw an error if address is not a valid derived address.
CTxDestination keyId;
keyId = address.Get();
if (boost::get<CNoDestination>(&keyId))
if (keyId.which() == ((CTxDestination)CNoDestination()).which())
throw std::invalid_argument(std::string(std::string(__func__) +
": invalid key id"));

Expand Down
2 changes: 1 addition & 1 deletion src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
} else if(index.column() == Address) {
CTxDestination newAddress = CBitcoinAddress(value.toString().toStdString()).Get();
// Refuse to set invalid address, set error status and return false
if(boost::get<CNoDestination>(&newAddress))
if (newAddress.which() == ((CTxDestination)CNoDestination()).which())
{
editStatus = INVALID_ADDRESS;
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,8 @@ UniValue querywhitelist(const JSONRPCRequest& request)
//Will throw an error if address is not a valid derived address.
CTxDestination keyId;
keyId = address.Get();
if (boost::get<CNoDestination>(&keyId))
//The which function for boost variant returns an index which represents the type of variant in order.
if (keyId.which() == ((CTxDestination)CNoDestination()).which())
throw std::invalid_argument(std::string(std::string(__func__) +
": invalid key id"));

Expand Down Expand Up @@ -1904,7 +1905,7 @@ UniValue removefromwhitelist(const JSONRPCRequest& request)
//Will throw an error if address is not a valid derived address.
CTxDestination keyId;
keyId = address.Get();
if (boost::get<CNoDestination>(&keyId))
if (keyId.which() == ((CTxDestination)CNoDestination()).which())
throw std::invalid_argument(std::string(std::string(__func__) +
": invalid key id"));

Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ bool CheckValidTweakedAddress(const CTxDestination keyID, const std::vector<CPub
//Will throw an error if address is not a valid derived address.
CTxDestination multiKeyId;
multiKeyId = address.Get();
if (boost::get<CNoDestination>(&multiKeyId))
if (multiKeyId.which() == ((CTxDestination)CNoDestination()).which())
return false;

if (!(multiKeyId == destCopy))
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ UniValue createkycfile(const JSONRPCRequest& request)
//Will skip if address is not a valid tweaked address.
CTxDestination multiKeyId;
multiKeyId = address.Get();
if (boost::get<CNoDestination>(&multiKeyId))
if (multiKeyId.which() == ((CTxDestination)CNoDestination()).which())
continue;

ss << strprintf("%d %s",
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ static void SendAddNextMultiToWhitelistTx(const CAsset& feeAsset, const CPubKey&
CRegisterAddressScript* raScript = new CRegisterAddressScript(RA_MULTISIG);

CTxDestination keyid = address.Get();
if (boost::get<CNoDestination>(&keyid))
if (keyid.which() == ((CTxDestination)CNoDestination()).which())
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string(std::string(__func__) +
": invalid key id"));

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2956,7 +2956,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
CScript scriptChange;

// coin control: send change to custom address
if (coinControl && !boost::get<CNoDestination>(&coinControl->destChange))
if (coinControl && !((coinControl->destChange).which() == ((CTxDestination)CNoDestination()).which()))
scriptChange = GetScriptForDestination(coinControl->destChange);

// no coin control: send change to newly generated address
Expand Down Expand Up @@ -4168,7 +4168,7 @@ void CWallet::GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) c

bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
{
if (boost::get<CNoDestination>(&dest))
if (dest.which() == ((CTxDestination)CNoDestination()).which())
return false;

mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
Expand Down

0 comments on commit 65fb702

Please sign in to comment.