Add test showing that the witness cache isn't being serialised
This commit is contained in:
parent
32a103aab7
commit
ac91ebbe92
|
@ -146,6 +146,29 @@ CWalletTx GetValidSpend(const libzcash::SpendingKey& sk,
|
||||||
return wtx;
|
return wtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(wallet_tests, note_data_serialisation) {
|
||||||
|
auto sk = libzcash::SpendingKey::random();
|
||||||
|
auto wtx = GetValidReceive(sk, 10, true);
|
||||||
|
auto note = GetNote(sk, wtx, 0, 1);
|
||||||
|
auto nullifier = note.nullifier(sk);
|
||||||
|
|
||||||
|
mapNoteData_t noteData;
|
||||||
|
JSOutPoint jsoutpt {wtx.GetTxid(), 0, 1};
|
||||||
|
CNoteData nd {sk.address(), nullifier};
|
||||||
|
ZCIncrementalMerkleTree tree;
|
||||||
|
nd.witnesses.push_front(tree.witness());
|
||||||
|
noteData[jsoutpt] = nd;
|
||||||
|
|
||||||
|
CDataStream ss(SER_DISK, CLIENT_VERSION);
|
||||||
|
ss << noteData;
|
||||||
|
|
||||||
|
mapNoteData_t noteData2;
|
||||||
|
ss >> noteData2;
|
||||||
|
|
||||||
|
EXPECT_EQ(noteData, noteData2);
|
||||||
|
EXPECT_EQ(noteData[jsoutpt].witnesses, noteData2[jsoutpt].witnesses);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(wallet_tests, set_note_addrs_in_cwallettx) {
|
TEST(wallet_tests, set_note_addrs_in_cwallettx) {
|
||||||
auto sk = libzcash::SpendingKey::random();
|
auto sk = libzcash::SpendingKey::random();
|
||||||
auto wtx = GetValidReceive(sk, 10, true);
|
auto wtx = GetValidReceive(sk, 10, true);
|
||||||
|
|
|
@ -43,10 +43,19 @@ public:
|
||||||
Hash empty_root(size_t depth) {
|
Hash empty_root(size_t depth) {
|
||||||
return empty_roots.at(depth);
|
return empty_roots.at(depth);
|
||||||
}
|
}
|
||||||
|
template <size_t D, typename H>
|
||||||
|
friend bool operator==(const EmptyMerkleRoots<D, H>& a,
|
||||||
|
const EmptyMerkleRoots<D, H>& b);
|
||||||
private:
|
private:
|
||||||
boost::array<Hash, Depth+1> empty_roots;
|
boost::array<Hash, Depth+1> empty_roots;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<size_t Depth, typename Hash>
|
||||||
|
bool operator==(const EmptyMerkleRoots<Depth, Hash>& a,
|
||||||
|
const EmptyMerkleRoots<Depth, Hash>& b) {
|
||||||
|
return a.empty_roots == b.empty_roots;
|
||||||
|
}
|
||||||
|
|
||||||
template<size_t Depth, typename Hash>
|
template<size_t Depth, typename Hash>
|
||||||
class IncrementalWitness;
|
class IncrementalWitness;
|
||||||
|
|
||||||
|
@ -90,6 +99,10 @@ public:
|
||||||
return emptyroots.empty_root(Depth);
|
return emptyroots.empty_root(Depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t D, typename H>
|
||||||
|
friend bool operator==(const IncrementalMerkleTree<D, H>& a,
|
||||||
|
const IncrementalMerkleTree<D, H>& b);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static EmptyMerkleRoots<Depth, Hash> emptyroots;
|
static EmptyMerkleRoots<Depth, Hash> emptyroots;
|
||||||
boost::optional<Hash> left;
|
boost::optional<Hash> left;
|
||||||
|
@ -104,6 +117,15 @@ private:
|
||||||
void wfcheck() const;
|
void wfcheck() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<size_t Depth, typename Hash>
|
||||||
|
bool operator==(const IncrementalMerkleTree<Depth, Hash>& a,
|
||||||
|
const IncrementalMerkleTree<Depth, Hash>& b) {
|
||||||
|
return (a.emptyroots == b.emptyroots &&
|
||||||
|
a.left == b.left &&
|
||||||
|
a.right == b.right &&
|
||||||
|
a.parents == b.parents);
|
||||||
|
}
|
||||||
|
|
||||||
template <size_t Depth, typename Hash>
|
template <size_t Depth, typename Hash>
|
||||||
class IncrementalWitness {
|
class IncrementalWitness {
|
||||||
friend class IncrementalMerkleTree<Depth, Hash>;
|
friend class IncrementalMerkleTree<Depth, Hash>;
|
||||||
|
@ -130,6 +152,10 @@ public:
|
||||||
cursor_depth = tree.next_depth(filled.size());
|
cursor_depth = tree.next_depth(filled.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t D, typename H>
|
||||||
|
friend bool operator==(const IncrementalWitness<D, H>& a,
|
||||||
|
const IncrementalWitness<D, H>& b);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IncrementalMerkleTree<Depth, Hash> tree;
|
IncrementalMerkleTree<Depth, Hash> tree;
|
||||||
std::vector<Hash> filled;
|
std::vector<Hash> filled;
|
||||||
|
@ -139,6 +165,15 @@ private:
|
||||||
IncrementalWitness(IncrementalMerkleTree<Depth, Hash> tree) : tree(tree) {}
|
IncrementalWitness(IncrementalMerkleTree<Depth, Hash> tree) : tree(tree) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<size_t Depth, typename Hash>
|
||||||
|
bool operator==(const IncrementalWitness<Depth, Hash>& a,
|
||||||
|
const IncrementalWitness<Depth, Hash>& b) {
|
||||||
|
return (a.tree == b.tree &&
|
||||||
|
a.filled == b.filled &&
|
||||||
|
a.cursor == b.cursor &&
|
||||||
|
a.cursor_depth == b.cursor_depth);
|
||||||
|
}
|
||||||
|
|
||||||
class SHA256Compress : public uint256 {
|
class SHA256Compress : public uint256 {
|
||||||
public:
|
public:
|
||||||
SHA256Compress() : uint256() {}
|
SHA256Compress() : uint256() {}
|
||||||
|
|
Loading…
Reference in New Issue