Reenable test bigchain api - part 1#2415
Conversation
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
Solution: Remove core.py. Refactor BigchainDB Class to remove inheritance from Bigchain.
…its, as I don't know what I'm doing, and I can't experiment without running the CI... Sorry in advance!
…its, as I don't know what I'm doing, and I can't experiment without running the CI... Sorry in advance!
…gchaindb into z-bowen-remove_bigchain_class
…ivate method, so I had to align with that.
Solution: resolved merge conflicts to excavate Block class from my branch
Solution: Merged and repushed
Solution: Merge changes into Master
…n_api.py` were disabled Solution: Fixed the tests that still made sense, and deleted the rest.
tests/conftest.py
Outdated
| from bigchaindb.models import Transaction | ||
| # create blocks with transactions for `USER` to spend | ||
| for block in range(4): | ||
| print('Fuck you') |
There was a problem hiding this comment.
I think we should remove this.
tests/db/test_bigchain_api.py
Outdated
|
|
||
| class TestBigchainApi(object): | ||
|
|
||
| @pytest.mark.genesis |
There was a problem hiding this comment.
The genesis marker should not be needed anymore
Solution: Made things prettier
Codecov Report
@@ Coverage Diff @@
## master #2415 +/- ##
=========================================
+ Coverage 88.16% 88.2% +0.03%
=========================================
Files 40 40
Lines 2298 2297 -1
=========================================
Hits 2026 2026
+ Misses 272 271 -1 |
Solution: Deleted the debugging comments
Solution: Removed the decorator
| from bigchaindb.models import Transaction | ||
| # create blocks with transactions for `USER` to spend | ||
| for block in range(4): | ||
| for height in range(1, 4): |
There was a problem hiding this comment.
height 0 is assumed for genesis block although changing to range(0,3) shouldn't matter either
| vote = b.vote(block3.id, b.get_last_voted_block().id, True) | ||
| b.write_vote(vote) | ||
|
|
||
| with pytest.raises(CriticalDoubleInclusion): |
There was a problem hiding this comment.
Now when you updated these tests you can remove CriticalDoubleInclusion from bigchaindb.exceptions.
| transfer_tx2 = transfer_tx2.sign([alice.private_key]) | ||
| block3 = b.create_block([transfer_tx2]) | ||
| b.write_block(block3) | ||
| with pytest.raises(OperationError): |
There was a problem hiding this comment.
Judging by the name and the previous code of the test, we need to test that BigchainDB.get_spent raisesCriticalDoubleSpend here.
There was a problem hiding this comment.
No, this isn't a test for a double spend. It's testing that you can't have two txs with the same tx_id
There was a problem hiding this comment.
It's called test_get_spent_with_double_inclusion_detected and it was calling b.get_spent(tx.id, 0) expecting it to raise CriticalDoubleInclusion, which is like double spend that somehow sneaked into the database. Currently, BigchainDB.get_spent raises core_exceptions.CriticalDoubleSpend and DoubleSpend, which is what we by analogy need to test now.
| vote = b.vote(block3.id, b.get_last_voted_block().id, True) | ||
| b.write_vote(vote) | ||
| with pytest.raises(DoubleSpend): | ||
| b.validate_transaction(transfer_tx2, [transfer_tx]) |
There was a problem hiding this comment.
Also judging by the previous state, we should test how BigchainDB.get_spent raises DoubleSpend when called with current_transactions=[transfer_tx].
There was a problem hiding this comment.
This is actually the method that ends up throwing the error in this test. See bigchaindb/models.py:59-63.
This is a bit over complicated for a unit test (we should probably be invoking that method directly,) but it is covered, so I don't think we need an additional test for it.
There was a problem hiding this comment.
What works for me is keeping everything as it is. I change all the block creation to a store_bulk_transaction and in the end when I call
with pytest.raises(CriticalDoubleSpend):
b.get_spent(tx.id, 0)
the CriticalDoubleSpend is raised and the test passes.
There was a problem hiding this comment.
I think later on in the file we test an actual DoubleSpend. With this it's doubled.
There was a problem hiding this comment.
The duplicate coverage is in the second test class, which hasn't been cleaned up yet, so I'm not removing my original asserts, but I added the assertion you requested
There was a problem hiding this comment.
But then this one will be doubled?
| # vote the first block invalid | ||
| vote = b.vote(block1.id, b.get_last_voted_block().id, False) | ||
| b.write_vote(vote) | ||
| with pytest.raises(OperationError): |
There was a problem hiding this comment.
Does this test differ somehow from the one before the one above?
There was a problem hiding this comment.
Other than that the first test is for a transfer and this is for a new asset, no. I don't know if that's a significant enough difference to justify a second test, but it's already written, so...
There was a problem hiding this comment.
It seems that this test tries to brute force storing a duplicate transaction and the above one tries to check if the double spend transaction in fact raises an exception when validate_transaction is called.
| def test_create_genesis_block_fails_if_table_not_empty(self, b): | ||
| from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError | ||
|
|
||
| with pytest.raises(GenesisBlockAlreadyExistsError): |
There was a problem hiding this comment.
This exception can be removed from bigchaindb/common/exceptions.py now.
…e in the code Solution: Deleted it
| tx.validate(b) | ||
|
|
||
|
|
||
| class TestTransactionValidation(object): |
There was a problem hiding this comment.
There are tests still disabled starting from this one. Do you plan to enable them in a separate PR?
There was a problem hiding this comment.
Yes. I'll keep working on this until I've done all the tests in this file, but this seemed like a natural break point where I could commit some functionality.
There was a problem hiding this comment.
Yes, I think we should merge this one and make a part two PR instead. The file has just too many changes in the end
Solution: Deleted it
tests/db/test_bigchain_api.py
Outdated
| @@ -216,12 +88,7 @@ def test_text_search(self, b, alice): | |||
| asset=asset3).sign([alice.private_key]) | |||
|
|
|||
| # create the block | |||
There was a problem hiding this comment.
this needs to be removed or changed
There was a problem hiding this comment.
Are you referring to the comment about creating the block, or something in the code?
There was a problem hiding this comment.
the comment, we don't create a block here anymore
| } | ||
|
|
||
| @pytest.mark.usefixtures('inputs') | ||
| def test_write_transaction(self, b, user_pk, user_sk): |
There was a problem hiding this comment.
why did you remove this one?
| assert tx_from_db.to_dict() == tx.to_dict() | ||
|
|
||
| @pytest.mark.usefixtures('inputs') | ||
| def test_read_transaction(self, b, user_pk, user_sk): |
There was a problem hiding this comment.
same here, why is it removed?
There was a problem hiding this comment.
I replaced the first test. This one seems very similar to the first... Basically, we write something to the DB, get it back, and check that nothing has changed. I don't see a way to keep these tests distinct with BDB2.0
… that everything is stored faithfully Solution: Replaced it and got it working again
Problem: Tests in class
TestBigChainAPIfromtests/db/test_bigchain_api.pywere disabledSolution
Fixed the tests that still made sense, and deleted the rest.