diff --git a/include/blockchain.h b/include/blockchain.h index abbb04c..a731ddd 100644 --- a/include/blockchain.h +++ b/include/blockchain.h @@ -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. * diff --git a/src/blockchain.c b/src/blockchain.c index 3edb1f1..dfbebcd 100644 --- a/src/blockchain.c +++ b/src/blockchain.c @@ -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, @@ -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); @@ -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, @@ -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; diff --git a/src/main.c b/src/main.c index 6498698..8548995 100644 --- a/src/main.c +++ b/src/main.c @@ -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) { diff --git a/tests/main.c b/tests/main.c index 8c054e5..63cf909 100644 --- a/tests/main.c +++ b/tests/main.c @@ -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) { @@ -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), diff --git a/tests/test_blockchain.c b/tests/test_blockchain.c index 0572fdc..97249e4 100644 --- a/tests/test_blockchain.c +++ b/tests/test_blockchain.c @@ -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( @@ -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); diff --git a/tests/test_blockchain.h b/tests/test_blockchain.h index 80fec0e..82475cb 100644 --- a/tests/test_blockchain.h +++ b/tests/test_blockchain.h @@ -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();