Skip to content

Commit

Permalink
keep tests unchanged from 0.27 ref skycoin#34
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Denis committed Aug 26, 2019
1 parent bdce11a commit 175d7fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
33 changes: 24 additions & 9 deletions lib/cgo/tests/check_cipher.address.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ START_TEST(TestAddressRoundtrip)
error = SKY_cipher_AddressFromPubKey(&p, &a);
ck_assert_int_eq(error, SKY_OK);
unsigned char buffera_bytes[1024];
coin__UxArray a_bytes = {buffera_bytes, 0, 1024};
GoSlice_ a_bytes = {buffera_bytes, 0, 1024};
error = SKY_cipher_Address_Bytes(&a, &a_bytes);
ck_assert_int_eq(error, SKY_OK);
cipher__Address a2;
Expand All @@ -45,7 +45,7 @@ START_TEST(TestAddressString)
cipher__PubKey pk;
cipher__SecKey sk;
cipher__Address addr, addr2, addr3;
GoUint8 buff[1024] = {0};
GoUint8 buff[1024];
GoString str = {buff, 0};

GoUint32 err = SKY_cipher_GenerateKeyPair(&pk, &sk);
Expand Down Expand Up @@ -102,13 +102,13 @@ END_TEST

START_TEST(TestDecodeBase58Address)
{
GoString strAddr = {.p = SKYCOIN_ADDRESS_VALID, .n = 35};
GoString strAddr = {SKYCOIN_ADDRESS_VALID, 35};
cipher__Address addr;
GoUint32 err = SKY_cipher_DecodeBase58Address(strAddr, &addr);
ck_assert_int_eq(err, SKY_OK);
GoUint8 buff[1024];
char tempStr[50];
GoUint32 errorcode;
int errorcode;

// preceding whitespace is invalid
strcpy(tempStr, " ");
Expand Down Expand Up @@ -150,10 +150,7 @@ START_TEST(TestDecodeBase58Address)
errorcode = SKY_cipher_AddressFromPubKey(&p, &a);
ck_assert(errorcode == SKY_OK);
GoSlice b;
coin__UxArray Cub;
Cub.data = buff;
Cub.len = 0;
Cub.cap = sizeof(buff);
GoSlice_ Cub = {buff, 0, 1024};
errorcode = SKY_cipher_Address_Bytes(&addr, &Cub);
ck_assert_msg(errorcode == SKY_OK, "Fail SKY_cipher_Address_Bytes");
b.cap = Cub.cap;
Expand All @@ -173,7 +170,6 @@ START_TEST(TestDecodeBase58Address)
errorcode = SKY_cipher_DecodeBase58Address(tmph, &addr);
ck_assert_msg(errorcode == SKY_ErrAddressInvalidLength, "Fail %X", errorcode);
b.len = len_b;
h.n = sizeof(bufferHead);
errorcode = SKY_base58_Hex2Base58(b, &h);
ck_assert(errorcode == SKY_OK);
tmph.n = h.n;
Expand All @@ -183,6 +179,24 @@ START_TEST(TestDecodeBase58Address)
}
END_TEST

START_TEST(TestAddressFromSecKey)
{
GoUint32 result;
cipher__PubKey p;
cipher__SecKey s;
result = SKY_cipher_GenerateKeyPair(&p, &s);
ck_assert_msg(result == SKY_OK, "SKY_cipher_GenerateKeyPair failed");
cipher__Address a;
result = SKY_cipher_AddressFromSecKey(&s, &a);
ck_assert_int_eq(result, SKY_OK);
result = SKY_cipher_Address_Verify(&a, &p);
ck_assert_int_eq(result, SKY_OK);
cipher__SecKey s2;
result = SKY_cipher_AddressFromSecKey(&s, &a);
ck_assert_int_eq(result, SKY_ERROR);
}
END_TEST

// define test suite and cases
Suite* check_cipher_address(void)
{
Expand All @@ -194,6 +208,7 @@ Suite* check_cipher_address(void)
tcase_add_test(tc, TestAddressRoundtrip);
tcase_add_test(tc, TestAddressString);
tcase_add_test(tc, TestAddressBulk);
tcase_add_test(tc, TestAddressFromSecKey);
tcase_add_test(tc, TestDecodeBase58Address);

return s;
Expand Down
17 changes: 7 additions & 10 deletions lib/cgo/tests/check_cipher.address.common.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#include <stdio.h>
#include <stdlib.h>

#include <check.h>
#include <string.h>

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

#define SKYCOIN_ADDRESS_VALID "2GgFvqoyk9RjwVzj8tqfcXVXB4orBwoc9qv"

Expand Down Expand Up @@ -113,14 +110,14 @@ END_TEST
// define test suite and cases
Suite* common_check_cipher_address(void)
{
Suite* s = suite_create("Load common_check_cipher_address.address");
Suite* s = suite_create("Load cipher.address.common");
TCase* tc;

tc = tcase_create("check_cipher.address.common");
tc = tcase_create("cipher.address.common");
tcase_add_checked_fixture(tc, setup, teardown);
tcase_add_test(tc, TestAddressFromBytes);
tcase_add_test(tc, TestAddressVerify);
tcase_add_test(tc, TestAddressNull);
tcase_add_test(tc, TestAddressFromBytes);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down

0 comments on commit 175d7fa

Please sign in to comment.