tests: fix hashchain unit tests

and relax the not-empty safety check to stay more intuitiuve
This commit is contained in:
moneromooo-monero 2017-10-03 00:51:53 +01:00
parent a2041c9874
commit 452d4fae39
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 2 additions and 2 deletions

View file

@ -108,7 +108,7 @@ namespace tools
void crop(size_t height) { m_blockchain.resize(height - m_offset); } void crop(size_t height) { m_blockchain.resize(height - m_offset); }
void clear() { m_offset = 0; m_blockchain.clear(); } void clear() { m_offset = 0; m_blockchain.clear(); }
bool empty() const { return m_blockchain.empty() && m_offset == 0; } bool empty() const { return m_blockchain.empty() && m_offset == 0; }
void trim(size_t height) { while (height > m_offset+1 && m_blockchain.size() > 1) { m_blockchain.pop_front(); ++m_offset; } m_blockchain.shrink_to_fit(); } void trim(size_t height) { while (height > m_offset && m_blockchain.size() > 1) { m_blockchain.pop_front(); ++m_offset; } m_blockchain.shrink_to_fit(); }
void refill(const crypto::hash &hash) { m_blockchain.push_back(hash); --m_offset; } void refill(const crypto::hash &hash) { m_blockchain.push_back(hash); --m_offset; }
template <class t_archive> template <class t_archive>

View file

@ -122,7 +122,7 @@ TEST(hashchain, trim)
ASSERT_EQ(hashchain.size(), 3); ASSERT_EQ(hashchain.size(), 3);
ASSERT_EQ(hashchain[2], make_hash(3)); ASSERT_EQ(hashchain[2], make_hash(3));
hashchain.trim(3); hashchain.trim(3);
ASSERT_EQ(hashchain.offset(), 3); ASSERT_EQ(hashchain.offset(), 2); // never gets it empty
ASSERT_EQ(hashchain.size(), 3); ASSERT_EQ(hashchain.size(), 3);
ASSERT_FALSE(hashchain.empty()); ASSERT_FALSE(hashchain.empty());
ASSERT_EQ(hashchain.genesis(), make_hash(1)); ASSERT_EQ(hashchain.genesis(), make_hash(1));