Skip to content

Reenable test bigchain api - part 1#2415

Merged
codegeschrei merged 30 commits intobigchaindb:masterfrom
z-bowen:reenable-test_bigchain_api
Aug 13, 2018
Merged

Reenable test bigchain api - part 1#2415
codegeschrei merged 30 commits intobigchaindb:masterfrom
z-bowen:reenable-test_bigchain_api

Conversation

@z-bowen
Copy link
Copy Markdown
Contributor

@z-bowen z-bowen commented Jul 27, 2018

Problem: Tests in class TestBigChainAPI from tests/db/test_bigchain_api.py were disabled

Solution

Fixed the tests that still made sense, and deleted the rest.

z-bowen added 20 commits June 28, 2018 12:01
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!
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.
@z-bowen z-bowen requested review from kansi, ldmberman and ttmc July 27, 2018 14:12
from bigchaindb.models import Transaction
# create blocks with transactions for `USER` to spend
for block in range(4):
print('Fuck you')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XD


class TestBigchainApi(object):

@pytest.mark.genesis
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The genesis marker should not be needed anymore

Solution: Made things prettier
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 27, 2018

Codecov Report

Merging #2415 into master will increase coverage by 0.03%.
The diff coverage is n/a.

@@            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

from bigchaindb.models import Transaction
# create blocks with transactions for `USER` to spend
for block in range(4):
for height in range(1, 4):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not range(0, 3)?

Copy link
Copy Markdown
Contributor

@kansi kansi Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when you updated these tests you can remove CriticalDoubleInclusion from bigchaindb.exceptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Done.

transfer_tx2 = transfer_tx2.sign([alice.private_key])
block3 = b.create_block([transfer_tx2])
b.write_block(block3)
with pytest.raises(OperationError):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Judging by the name and the previous code of the test, we need to test that BigchainDB.get_spent raisesCriticalDoubleSpend here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also judging by the previous state, we should test how BigchainDB.get_spent raises DoubleSpend when called with current_transactions=[transfer_tx].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think later on in the file we test an actual DoubleSpend. With this it's doubled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test differ somehow from the one before the one above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception can be removed from bigchaindb/common/exceptions.py now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

tx.validate(b)


class TestTransactionValidation(object):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are tests still disabled starting from this one. Do you plan to enable them in a separate PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@codegeschrei codegeschrei Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@kansi kansi mentioned this pull request Jul 29, 2018
16 tasks
@ttmc ttmc removed their request for review July 29, 2018 13:12
@ttmc ttmc changed the title Reenable test bigchain api Reenable test bigchain api - part 1 Jul 29, 2018
@@ -216,12 +88,7 @@ def test_text_search(self, b, alice):
asset=asset3).sign([alice.private_key])

# create the block
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be removed or changed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to the comment about creating the block, or something in the code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment, we don't create a block here anymore

}

@pytest.mark.usefixtures('inputs')
def test_write_transaction(self, b, user_pk, user_sk):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, why is it removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants