Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15 implement verification #44

Merged
merged 39 commits into from
May 30, 2017
Merged

15 implement verification #44

merged 39 commits into from
May 30, 2017

Conversation

chadlagore
Copy link
Contributor

@chadlagore chadlagore commented May 30, 2017

Status: Ready for review.

What Changed

  • Covered an additional test case to detect to transactions that already exist within the BlockChain (respend attack) - test case TestTransactionRespend.
  • Added some new helper methods: BlockChain.AppendBlock and Block.ContainsTransaction.
  • Refactored the tests.

Refactor largely due to the fact that many of the tests were testing transactions that already existed within the BlockChain. While this is a reasonable exercise, we want to focus on testing new transactions (transactions lacking consensus).

How To Test Drive This PR

  1. 👀
  2. 🏃 go test
  3. 💵 profit

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 89.583% when pulling 23fb1fb on 15-implement-verification into c61ff55 on dev.

Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

Couple of minor things. Awesome tests


// ContainsTransaction returns true and the transaction itself if the Block
// contains the transaction.
func (b *Block) ContainsTransaction(t *Transaction) bool {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -70,3 +70,14 @@ func DecodeBlock(r io.Reader) *Block {
gob.NewDecoder(r).Decode(&b)
return &b
}

// ContainsTransaction returns true and the transaction itself if the Block
// contains the transaction.
Copy link
Member

Choose a reason for hiding this comment

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

"and the transaction itself"?

Copy link
Contributor Author

@chadlagore chadlagore May 30, 2017

Choose a reason for hiding this comment

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

Seems like the right thing to do doesn't it. Breaks my if block.ContainsTransaction(t) then idiom 😢 Forgot the comment in there 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💡

hash := HashSum(t.TxBody)
if !ecdsa.Verify(t.Sender.Key(), hash.Marshal(), t.Sig.R, t.Sig.S) {
return false
}

// Validate chain from input block to last block.
// Test if identical transaction already exits in chain.
Copy link
Member

Choose a reason for hiding this comment

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

exists

@@ -123,7 +123,8 @@ func newTransactionValue(s, r Wallet, a uint64) (*Transaction, error) {
return tbody.Sign(s, crand.Reader)
}

func newValidBlockChainFixture() *BlockChain {
// newValidBlockChainFixture creates a valid blockchain of two blocks.
func newValidBlockChainFixture() (*BlockChain, Wallet) {
Copy link
Member

Choose a reason for hiding this comment

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

These test utils are awesome 🥇

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 89.583% when pulling 10282cf on 15-implement-verification into c61ff55 on dev.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) to 89.583% when pulling eceaaf9 on 15-implement-verification into c61ff55 on dev.

@chadlagore chadlagore merged commit c7d29b5 into dev May 30, 2017
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.

None yet

3 participants