Skip to content

Commit

Permalink
Fixed linting
Browse files Browse the repository at this point in the history
Signed-off-by: leonard.kosta <[email protected]>
  • Loading branch information
kostaleonard committed Feb 16, 2024
1 parent 9417eb5 commit 9834d41
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 61 deletions.
26 changes: 0 additions & 26 deletions include/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,6 @@ return_code_t blockchain_mine_block(
*/
void blockchain_print(blockchain_t *blockchain);

/**
* @brief Verifies that the blockchain is valid.
*
* A blockchain is valid if it meets the following conditions.
*
* 1. Every block has a valid proof of work. For every block other than the
* genesis block, the block must hash to a value that contains the number of
* leading zero bytes in the blockchain data structure. The genesis block must
* have the magic number proof of work GENESIS_BLOCK_PROOF_OF_WORK and be the
* first block.
* 2. Every block must have a correct previous block hash. For the genesis
* block, the previous block hash must be zero.
* 3. Every transaction in every block must have a valid digital signature.
*
* @param blockchain The blockchain.
* @param is_valid_blockchain A pointer to fill with the result.
* @param first_invalid_block If the blockchain is invalid and this argument is
* not NULL, the function fills this pointer with the first invalid block.
* @return return_code_t A return code indicating success or failure.
*/
return_code_t blockchain_verify(
blockchain_t *blockchain,
bool *is_valid_blockchain,
block_t **first_invalid_block
);

/**
* @brief Serializes the blockchain into a buffer for file or network I/O.
*
Expand Down
5 changes: 1 addition & 4 deletions src/blockchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ void blockchain_print(blockchain_t *blockchain) {
printf("\n");
}

// TODO add issue to use JSON serialization rather than binary
return_code_t blockchain_serialize(
blockchain_t *blockchain,
unsigned char **buffer,
Expand All @@ -207,7 +206,7 @@ return_code_t blockchain_serialize(
if (SUCCESS != return_code) {
goto end;
}
uint64_t size =
uint64_t size =
sizeof(blockchain->num_leading_zero_bytes_required_in_block_hash) +
sizeof(num_blocks);
unsigned char *serialization_buffer = calloc(1, size);
Expand Down Expand Up @@ -310,7 +309,6 @@ return_code_t blockchain_serialize(
return return_code;
}

// TODO make issue that this function is too complex, too hard to error-check
return_code_t blockchain_deserialize(
blockchain_t **blockchain,
unsigned char *buffer,
Expand Down Expand Up @@ -391,7 +389,6 @@ return_code_t blockchain_deserialize(
for (uint64_t transaction_idx = 0;
transaction_idx < num_transactions;
transaction_idx++) {
// TODO transaction_create interface doesn't allow us to pass in a signature directly, so I manually alloc--not sure if good or bad
transaction_t *transaction = calloc(1, sizeof(transaction_t));
if (NULL == transaction) {
return_code = FAILURE_COULD_NOT_MALLOC;
Expand Down
1 change: 0 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ return_code_t mine_blocks(
goto end;
}
while (true) {
// TODO verify blockchain here just before mining a new block
node_t *node = NULL;
return_code = linked_list_get_last(blockchain->block_list, &node);
if (SUCCESS != return_code) {
Expand Down
6 changes: 2 additions & 4 deletions tests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ int _unlink_callback(
const char *fpath,
const struct stat *sb,
int typeflag,
struct FTW *ftwbuf)
{
struct FTW *ftwbuf) {
struct stat st;
int return_value = stat(fpath, &st);
if (0 != return_value) {
Expand Down Expand Up @@ -143,9 +142,8 @@ int main(int argc, char **argv) {
cmocka_unit_test(
test_blockchain_mine_block_produces_block_with_valid_hash),
cmocka_unit_test(test_blockchain_mine_block_fails_on_invalid_input),
// TODO put these in the correct order
cmocka_unit_test(test_blockchain_serialize_creates_nonempty_buffer),
cmocka_unit_test(test_blockchain_serialize_fails_on_invalid_arguments),
cmocka_unit_test(test_blockchain_serialize_fails_on_invalid_input),
cmocka_unit_test(test_blockchain_deserialize_reconstructs_blockchain),
cmocka_unit_test(
test_blockchain_deserialize_fails_on_attempted_read_past_buffer),
Expand Down
26 changes: 1 addition & 25 deletions tests/test_blockchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,6 @@ void test_blockchain_mine_block_fails_on_invalid_input() {
blockchain_destroy(blockchain);
}

void test_blockchain_verify_succeeds_on_valid_blockchain() {
// TODO need to serialize blockchain and save as fixture
}

void test_blockchain_verify_fails_on_invalid_genesis_block() {
// TODO
}

void test_blockchain_verify_fails_on_invalid_proof_of_work() {
// TODO
}

void test_blockchain_verify_fails_on_invalid_previous_block_hash() {
// TODO
}

void test_blockchain_verify_fails_on_invalid_transaction_signature() {
// TODO
}

void test_blockchain_verify_fails_on_invalid_input() {
// TODO
}

void test_blockchain_serialize_creates_nonempty_buffer() {
blockchain_t *blockchain = NULL;
return_code_t return_code = blockchain_create(
Expand All @@ -302,7 +278,7 @@ void test_blockchain_serialize_creates_nonempty_buffer() {
blockchain_destroy(blockchain);
}

void test_blockchain_serialize_fails_on_invalid_arguments() {
void test_blockchain_serialize_fails_on_invalid_input() {
blockchain_t *blockchain = NULL;
return_code_t return_code = blockchain_create(
&blockchain, NUM_LEADING_ZERO_BYTES_IN_BLOCK_HASH);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void test_blockchain_mine_block_fails_on_invalid_input();

void test_blockchain_serialize_creates_nonempty_buffer();

void test_blockchain_serialize_fails_on_invalid_arguments();
void test_blockchain_serialize_fails_on_invalid_input();

void test_blockchain_deserialize_reconstructs_blockchain();

Expand Down

0 comments on commit 9834d41

Please sign in to comment.