-
Notifications
You must be signed in to change notification settings - Fork 2
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
Better testing for blockchain
#23
Conversation
blockchain
blockchain
29 makefile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me. But I'm a bit concerned about the validity of creating randomized test fixtures, makes replication of errors non-deterministic.
It would be nice to have the option to pass parameters to some of these fixtures as well (validating inputs and outputs).
} | ||
} | ||
|
||
func newTxOutput() TxOutput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These helpers are great, but perhaps we could expose a parameter generate this TxOutput
fixture in a way that is not random? Im thinking about testing valid transaction inputs and outputs 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work my guy!
``` | ||
|
||
## Testing | ||
|
||
``` | ||
go test ./... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
miner Wallet | ||
BlockNumber uint32 | ||
LastBlock Hash | ||
Miner Address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of address will this be?
gob.NewDecoder(r).Decode(b) | ||
err := gob.NewEncoder(w).Encode(b) | ||
if err != nil { | ||
fmt.Println(err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably change this to a Log
statement at some point.
func (bc *BlockChain) Decode(r io.Reader) { | ||
gob.NewDecoder(r).Decode(bc) | ||
// DecodeBlockChain reads the marshalled blockchain from the given io.Reader | ||
func DecodeBlockChain(r io.Reader) *BlockChain { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we have to implement our own Blockchain io Reader to handle the format of the Blockchain in byte array format?
} | ||
|
||
// Marshaller is any type that can convert itself to a byte slice | ||
type Marshaller interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
mrand "math/rand" | ||
) | ||
|
||
func newHash() Hash { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does't one of the imports have a function that can do this for us?
} | ||
|
||
// Len returns the length of a transaction body | ||
func (tb TxBody) Len() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps func (tb *TxBody) Len() int
would be better here? Not sure about the semantics, but something to think about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes for other exported functions on structs as well.
No description provided.