def test_TestAddressVerify(): public_key = skycoin.cipher_PubKey() secret_key = skycoin.cipher_SecKey() skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key) address = skycoin.cipher__Address() skycoin.SKY_cipher_AddressFromPubKey(public_key, address) # Valid pubkey+address err = skycoin.SKY_cipher_Address_Verify(address, public_key) assert err == skycoin.SKY_OK # Invalid pubkey public_key_temp = skycoin.cipher_PubKey() err = skycoin.SKY_cipher_Address_Verify(address, public_key_temp) assert err == skycoin.SKY_ErrAddressInvalidPubKey skycoin.SKY_cipher_GenerateKeyPair(public_key_temp, secret_key) err = skycoin.SKY_cipher_Address_Verify(address, public_key_temp) assert err == skycoin.SKY_ErrAddressInvalidPubKey # Bad version address.Version = 0x01 err = skycoin.SKY_cipher_Address_Verify(address, public_key) assert err == skycoin.SKY_ErrAddressInvalidVersion
def test_TestPubKeyToAddress(): public_key = skycoin.cipher_PubKey() secret_key = skycoin.cipher_SecKey() skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key) addres = skycoin.cipher__Address() skycoin.SKY_cipher_AddressFromPubKey(public_key, addres) # func (self Address) Verify(key PubKey) error assert skycoin.SKY_cipher_Address_Verify(addres, public_key) == skycoin.SKY_OK # func DecodeBase58Address(addr string) (Address, error) _, addres_str = skycoin.SKY_cipher_Address_String(addres) assert skycoin.SKY_cipher_DecodeBase58Address(addres_str, addres) == skycoin.SKY_OK
def test_TestAddressBulk(): for _ in range(1024): public_key = skycoin.cipher_PubKey() secret_key = skycoin.cipher_SecKey() addres_1 = skycoin.cipher__Address() address_2 = skycoin.cipher__Address() _, data = skycoin.SKY_cipher_RandByte(32) skycoin.SKY_cipher_GenerateDeterministicKeyPair( data, public_key, secret_key) skycoin.SKY_cipher_AddressFromPubKey(public_key, addres_1) err = skycoin.SKY_cipher_Address_Verify(addres_1, public_key) assert err == skycoin.SKY_OK _, addres_str = skycoin.SKY_cipher_Address_String(addres_1) err = skycoin.SKY_cipher_DecodeBase58Address(addres_str, address_2) assert err == skycoin.SKY_OK assert addres_1 == address_2
def test_GenerateKeyPairs(): error, data = skycoin.SKY_cipher_RandByte(32) assert error == 0 pubkey = skycoin.cipher_PubKey() seckey = skycoin.cipher_SecKey() error = skycoin.SKY_cipher_GenerateDeterministicKeyPair(data, pubkey, seckey) assert error == 0 address = skycoin.cipher__Address() error = skycoin.SKY_cipher_AddressFromPubKey(pubkey, address) assert error == 0 error = skycoin.SKY_cipher_Address_Verify(address, pubkey) assert error == 0 error, address_string = skycoin.SKY_cipher_Address_String( address ) assert error == 0 address2 = skycoin.cipher__Address() error = skycoin.SKY_cipher_DecodeBase58Address( address_string, address2 ) assert error == 0 assert address.isEqual(address2)
def test_TestDecodeBase58Address(): public_key = skycoin.cipher_PubKey() secret_key = skycoin.cipher_SecKey() skycoin.SKY_cipher_GenerateKeyPair(public_key, secret_key) address = skycoin.cipher__Address() skycoin.SKY_cipher_AddressFromPubKey(public_key, address) err = skycoin.SKY_cipher_Address_Verify(address, public_key) assert err == skycoin.SKY_OK address_2 = skycoin.cipher__Address() err = skycoin.SKY_cipher_DecodeBase58Address(b'""', address_2) assert err == skycoin.SKY_ERROR err = skycoin.SKY_cipher_DecodeBase58Address(b'"cascs"', address_2) assert err == skycoin.SKY_ERROR _, byte = skycoin.SKY_cipher_Address_Bytes(address) _, h = skycoin.SKY_base58_Hex2Base58(byte[:int(len(byte) / 2)]) err = skycoin.SKY_cipher_DecodeBase58Address(h, address_2) assert err == skycoin.SKY_ErrAddressInvalidLength _, h = skycoin.SKY_base58_Hex2Base58(byte) err = skycoin.SKY_cipher_DecodeBase58Address(h, address_2) assert err == skycoin.SKY_OK assert address == address_2 _, addres_str = skycoin.SKY_cipher_Address_String(address) err = skycoin.SKY_cipher_DecodeBase58Address(addres_str, address_2) assert err == skycoin.SKY_OK assert address == address_2 # preceding whitespace is invalid addres_2_str = b'" " + a_str' err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2) assert err == skycoin.SKY_ERROR # preceding zeroes are invalid addres_2_str = b'"000" + a_str' err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2) assert err == skycoin.SKY_ERROR # trailing whitespace is invalid addres_2_str = b'a_str + " "' err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2) assert err == skycoin.SKY_ERROR # trailing zeroes are invalid addres_2_str = b'a_str + "000"' err = skycoin.SKY_cipher_DecodeBase58Address(addres_2_str, address_2) assert err == skycoin.SKY_ERROR