From e85fac5167daa8803a4d771c7d102aace6d8082d Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 14 Apr 2020 20:44:19 +1200 Subject: [PATCH 1/2] test: Ignore timestamps in addressindex checks The mempool timestamps are local to each node, and if the testing machine is under load, they can potentially differ by a second. Closes zcash/zcash#4439. Co-authored-by: Ying Tong --- qa/rpc-tests/addressindex.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index 5e87fc65d..30198a38a 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -208,7 +208,13 @@ class AddressIndexTest(BitcoinTestFramework): assert_equal(mempool[2]['txid'], txid) # a single address can be specified as a string (not json object) - assert_equal([mempool[1]], self.nodes[0].getaddressmempool(addr1)) + addr1_mempool = self.nodes[0].getaddressmempool(addr1) + assert_equal(len(addr1_mempool), 1) + # Don't check the timestamp; it's local to the node, and can mismatch + # due to propagation delay. + del addr1_mempool[0]['timestamp'] + for key in addr1_mempool[0].keys(): + assert_equal(mempool[1][key], addr1_mempool[0][key]) tx = self.nodes[0].getrawtransaction(txid, 1) assert_equal(tx['vin'][0]['address'], addr1) From f4194a3fd79aff36bc3b34924bba5d6c7c238bf7 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 14 Apr 2020 20:45:52 +1200 Subject: [PATCH 2/2] test: Add a second Sapling note to WalletTests.ClearNoteWitnessCache Quoting the documentation for `std::vector::operator[]`: Portable programs should never call this function with an argument n that is out of range, since this causes undefined behavior. This test was doing just that: performing checks on a non-existent second Sapling witness (duplicating the Sprout logic that checked two notes, one of which was in the wallet). The test was instead reading arbitrary memory after the witness that did exist; in most cases, this memory was interpreted as a `boost::none` as expected, but in some cases the memory was interpreted as a "real" witness. Closes zcash/zcash#4445. Co-authored-by: Ying Tong --- src/wallet/gtest/test_wallet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 458497e02..a2cb278ad 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -1511,7 +1511,15 @@ TEST(WalletTests, ClearNoteWitnessCache) { wallet.AddToWallet(wtx, true, NULL); + // For Sprout, we have two outputs in the one JSDescription, only one of + // which is in the wallet. std::vector sproutNotes {jsoutpt, jsoutpt2}; + // For Sapling, SetSaplingNoteData() only created a single Sapling output + // which is in the wallet, so we add a second SaplingOutPoint here to + // exercise the "note not in wallet" case. + saplingNotes.emplace_back(wtx.GetHash(), 1); + ASSERT_EQ(saplingNotes.size(), 2); + std::vector> sproutWitnesses; std::vector> saplingWitnesses;