-
Notifications
You must be signed in to change notification settings - Fork 20
test(conway): Create tests for creating block CBOR #1055
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
Conversation
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.
Our cbor.Encode()
function is nothing but a wrapper for the upstream cbor.Marshal()
function with the proper encoder mode set. We only need/want to test with our custom cbor.Encode()
, since the plain upstream function will produce different results in some cases.
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.
Is there a good reason to store this block as hex? It requires an extra step to decode, and it takes up 2x the disk space.
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.
I told him to store it as hex.
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 name this file in a way that tells us where it came from. We at least want the network name, block hash, and block slot, so that we can look it up again later
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.
I prefer we put it into a variable within the Go code rather than as a separate file we have to load, and we simply comment this information.
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.
I have removed the hex from the file and stored it inside the code itself. Added the information about block hash, block slot in the comments. Please review it once
ledger/conway/pparams_test.go
Outdated
} | ||
} | ||
|
||
func isValidHexString(s string) 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.
You won't need this. You're providing the string. You know it's good.
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.
I removed this extra validation check and please review it once.
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 are block tests. Create a block_test.go
file rather than putting tests not related to protocol parameters in this file.
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.
I have created a new file block_test.go and moved the tests to this file. Please review it once
ledger/conway/pparams_test.go
Outdated
|
||
func TestConwayBlock_CborRoundTrip_UsingCustomEncode(t *testing.T) { | ||
// Read the hex-encoded CBOR string for a Conway block | ||
filePath := filepath.Join("testdata", "conway_block.cbor.hex") |
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.
Put this into a string var instead of reading from disk. We can reuse it across the package without doing disk seeks in every test.
Something like:
// taken from https://cexplorer.io/block/abcd...
var conwayBlockHex string = "..."
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.
I have made the changes for this like stored in a variable
ledger/conway/pparams_test.go
Outdated
t.Errorf("Custom CBOR round-trip mismatch for Conway block\nOriginal CBOR (hex): %x\nCustom Encoded CBOR (hex): %x", dataBytes, encoded) | ||
} | ||
|
||
// Save the re-encoded CBOR for comparison |
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.
Skip this. The text/hex output is good enough.
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.
Removed this part like storing back again the rendered CBOR. Please review it once.
I have removed the test function with inbuilt |
b4364fd
to
5a84909
Compare
…ock to validate against original bytes Signed-off-by: Akhil Repala <[email protected]>
…s to block_test.go Signed-off-by: Akhil Repala <[email protected]>
…unction Signed-off-by: Akhil Repala <[email protected]>
5a84909
to
a8067f2
Compare
Closes #1043