Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestAddressVerify from lib/cgo/tests/check_cipher.address.c to
lib/cgo/tests/check_cipher.address.common.c
ref #84
  • Loading branch information
Alvaro Denis committed May 15, 2019
1 parent f6e0346 commit 3abff9d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
29 changes: 0 additions & 29 deletions lib/cgo/tests/check_cipher.address.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,6 @@ START_TEST(TestAddressFromBytes)
}
END_TEST

START_TEST(TestAddressVerify)
{
cipher__PubKey pubkey;
cipher__SecKey seckey;
cipher__PubKey pubkey2;
cipher__SecKey seckey2;
cipher__Address addr;

SKY_cipher_GenerateKeyPair(&pubkey, &seckey);
SKY_cipher_AddressFromPubKey(&pubkey, &addr);

// Valid pubkey+address
ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == SKY_OK,
"Valid pubkey + address");

SKY_cipher_GenerateKeyPair(&pubkey, &seckey2);
// Invalid pubkey
ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) ==
SKY_ErrAddressInvalidPubKey,
" Invalid pubkey");

// Bad version
addr.Version = 0x01;
ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) ==
SKY_ErrAddressInvalidVersion,
" Bad version");
}
END_TEST

START_TEST(TestAddressString)
{
cipher__PubKey pk;
Expand Down
52 changes: 52 additions & 0 deletions lib/cgo/tests/check_cipher.address.common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>

#include <check.h>
#include "libskycoin.h"
#include "skyerrors.h"
#include "skyassert.h"
#include "skystring.h"
#include "skytest.h"

START_TEST(TestAddressVerify)
{
cipher__PubKey pubkey;
cipher__SecKey seckey;
cipher__PubKey pubkey2;
cipher__SecKey seckey2;
cipher__Address addr;

SKY_cipher_GenerateKeyPair(&pubkey, &seckey);
SKY_cipher_AddressFromPubKey(&pubkey, &addr);

// Valid pubkey+address
ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) == SKY_OK,
"Valid pubkey + address");

SKY_cipher_GenerateKeyPair(&pubkey, &seckey2);
Invalid pubkey
ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) ==
SKY_ErrAddressInvalidPubKey,
" Invalid pubkey");

// Bad version
addr.Version = 0x01;
ck_assert_msg(SKY_cipher_Address_Verify(&addr, &pubkey) ==
SKY_ErrAddressInvalidVersion,
" Bad version");
}
END_TEST

// define test suite and cases
Suite *common_check_cipher_address(void)
{
Suite *s = suite_create("Load common check_cipher.address");
TCase *tc;

tc = tcase_create("check_cipher.address");
tcase_add_test(tc, TestAddressVerify);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

return s;
}
1 change: 1 addition & 0 deletions lib/cgo/tests/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ int main(void)
SRunner* sr = srunner_create(cipher_address());
SRunner* sr_fork = srunner_create(coin_transaction_fork());
srunner_add_suite(sr, common_check_cipher_hash());
srunner_add_suite(sr, common_check_cipher_address());
srunner_add_suite(sr, cipher_bitcoin());
srunner_add_suite(sr, cipher_crypto());
srunner_add_suite(sr, cipher_encrypt_scrypt_chacha20poly1305());
Expand Down
1 change: 1 addition & 0 deletions lib/cgo/tests/test_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "skytest.h"
#include "skytypes.h"
#include "skyerrors.h"
#include "test_main_common.h"

Suite *cipher_bitcoin(void);
Suite *cipher_address(void);
Expand Down
10 changes: 10 additions & 0 deletions lib/cgo/tests/test_main_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef TEST_MAIN_COMMON_H
#define TEST_MAIN_COMMON_H

#include <check.h>
#include <stdlib.h>

Suite *common_check_cipher_hash(void);
Suite *common_check_cipher_address(void);

#endif // TEST_MAIN_COMMON_H
3 changes: 2 additions & 1 deletion lib/cgo/tests/test_main_hw.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include <check.h>
#include <stdlib.h>

Suite *common_check_cipher_hash(void);
#include "test_main_common.h"

// run suite
int main(void)
{
int number_failed = 0;
int number_failed_fork = 0;
SRunner *sr = srunner_create(common_check_cipher_hash());
srunner_add_suite(sr, common_check_cipher_address());
srunner_run_all(sr, CK_VERBOSE);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
Expand Down

0 comments on commit 3abff9d

Please sign in to comment.