Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move TestDecodeBase58Address from lib/cgo/tests/check_cipher.address.c to lib/cgo/tests/check_cipher.address.common.c
finally removed lib/cgo/tests/check_cipher.address.c as all address related test can be run against hardware wallet
ref #34
  • Loading branch information
Alvaro Denis committed May 15, 2019
1 parent 9a90451 commit 66fd014
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 111 deletions.
111 changes: 0 additions & 111 deletions lib/cgo/tests/check_cipher.address.c

This file was deleted.

85 changes: 85 additions & 0 deletions lib/cgo/tests/check_cipher.address.common.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "skystring.h"
#include "skytest.h"

#define SKYCOIN_ADDRESS_VALID "2GgFvqoyk9RjwVzj8tqfcXVXB4orBwoc9qv"

// buffer big enough to hold all kind of data needed by test cases
unsigned char buff[1024];

Expand Down Expand Up @@ -168,6 +170,88 @@ START_TEST(TestAddressFromBytes)
}
END_TEST

START_TEST(TestDecodeBase58Address)
{
GoString strAddr = {SKYCOIN_ADDRESS_VALID, 35};
cipher__Address addr;
GoUint32 err = SKY_cipher_DecodeBase58Address(strAddr, &addr);
ck_assert_int_eq(err, SKY_OK);

char tempStr[50];
int errorcode;

// preceding whitespace is invalid
strcpy(tempStr, " ");
strcat(tempStr, SKYCOIN_ADDRESS_VALID);
strAddr.p = tempStr;
strAddr.n = strlen(tempStr);
errorcode = SKY_cipher_DecodeBase58Address(strAddr, &addr);
ck_assert_msg(errorcode == SKY_ERROR, "preceding whitespace is invalid");

// preceding zeroes are invalid
strcpy(tempStr, "000");
strcat(tempStr, SKYCOIN_ADDRESS_VALID);
strAddr.p = tempStr;
strAddr.n = strlen(tempStr);
errorcode = SKY_cipher_DecodeBase58Address(strAddr, &addr);
ck_assert_msg(errorcode == SKY_ERROR, "leading zeroes prefix are invalid");

// trailing whitespace is invalid
strcpy(tempStr, SKYCOIN_ADDRESS_VALID);
strcat(tempStr, " ");
strAddr.p = tempStr;
strAddr.n = strlen(tempStr);
errorcode = SKY_cipher_DecodeBase58Address(strAddr, &addr);
ck_assert_msg(errorcode == SKY_ERROR, "trailing whitespace is invalid");

// trailing zeroes are invalid
strcpy(tempStr, SKYCOIN_ADDRESS_VALID);
strcat(tempStr, "000");
strAddr.p = tempStr;
strAddr.n = strlen(tempStr);
errorcode = SKY_cipher_DecodeBase58Address(strAddr, &addr);
ck_assert_msg(errorcode == SKY_ERROR, "trailing zeroes suffix are invalid");

cipher__PubKey p;
cipher__SecKey s;
errorcode = SKY_cipher_GenerateKeyPair(&p, &s);
ck_assert(errorcode == SKY_OK);
cipher__Address a;
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);
errorcode = SKY_cipher_Address_Bytes(&addr, &Cub);
ck_assert_msg(errorcode == SKY_OK, "Fail SKY_cipher_Address_Bytes");
b.cap = Cub.cap;
b.data = Cub.data;
b.len = Cub.len;

int len_b = b.len;
char bufferHead[1024];
GoString_ h = {bufferHead, 0};
b.len = (GoInt)(len_b / 2);
errorcode = SKY_base58_Hex2Base58(b, &h);
ck_assert(errorcode == SKY_OK);
char bufferHeadTmp[1024];
GoString tmph = {bufferHeadTmp, 0};
tmph.n = h.n;
tmph.p = h.p;
errorcode = SKY_cipher_DecodeBase58Address(tmph, &addr);
ck_assert_msg(errorcode == SKY_ErrAddressInvalidLength, "Fail %X", errorcode);
b.len = len_b;
errorcode = SKY_base58_Hex2Base58(b, &h);
ck_assert(errorcode == SKY_OK);
tmph.n = h.n;
tmph.p = h.p;
errorcode = SKY_cipher_DecodeBase58Address(tmph, &addr);
ck_assert_msg(errorcode == SKY_OK, "Fail %X", errorcode);
}
END_TEST

// define test suite and cases
Suite *common_check_cipher_address(void)
{
Expand All @@ -180,6 +264,7 @@ Suite *common_check_cipher_address(void)
tcase_add_test(tc, TestAddressBulk);
tcase_add_test(tc, TestAddressNull);
tcase_add_test(tc, TestAddressFromBytes);
tcase_add_test(tc, TestDecodeBase58Address);
suite_add_tcase(s, tc);
tcase_set_timeout(tc, 150);

Expand Down

0 comments on commit 66fd014

Please sign in to comment.