def test_purchase_info_blobbing(): pi = vsp.PurchaseInfo.parse(purchaseInfo) b = vsp.PurchaseInfo.blob(pi) assert isinstance(b, bytearray) rePi = vsp.PurchaseInfo.unblob(b) assertPiIsEqual(rePi) ts = rePi.unixTimestamp assert isinstance(ts, int) and ts == pi.unixTimestamp # bad version bCopy = encode.ByteArray(b, copy=True) bCopy[0] = 255 with pytest.raises(NotImplementedError): vsp.PurchaseInfo.unblob(bCopy.bytes()) # too long bCopy = encode.ByteArray(b, copy=True) bCopy += b"\x00" with pytest.raises(DecredError): vsp.PurchaseInfo.unblob(bCopy.bytes())
def test_vsp_blobbing(): pool = vsp.VotingServiceProvider(**votingServiceProvider) b = vsp.VotingServiceProvider.blob(pool) assert isinstance(b, bytearray) rePool = vsp.VotingServiceProvider.unblob(b) assertVspIsEqual(rePool) ts = rePool.purchaseInfo.unixTimestamp assert isinstance(ts, int) and ts == pool.purchaseInfo.unixTimestamp # bad version bCopy = encode.ByteArray(b, copy=True) bCopy[0] = 255 with pytest.raises(NotImplementedError): vsp.VotingServiceProvider.unblob(bCopy.bytes()) # too long bCopy = encode.ByteArray(b, copy=True) bCopy += b"\x00" with pytest.raises(DecredError): vsp.VotingServiceProvider.unblob(bCopy.bytes())
def test_vsp_serialize(): pool = vsp.VotingServiceProvider(**votingServiceProvider) b = vsp.VotingServiceProvider.blob(pool) assert pool.serialize() == encode.ByteArray(b)
""" Copyright (c) 2019-2020, the Decred developers See LICENSE for details """ import pytest from decred import DecredError from decred.crypto import crypto, rando from decred.dcr import addrlib, nets from decred.util import chains, database, encode from decred.wallet import accounts testSeed = encode.ByteArray( "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef").b tRoot = crypto.ExtendedKey.new(testSeed) def test_child_neuter(prepareLogger): """ Test the ExtendedKey.neuter method. """ extKey = crypto.ExtendedKey.new(testSeed) extKey.setNetwork(nets.mainnet) extKey.child(0) pub = extKey.neuter() expStr = ( "dpubZ9169KDAEUnyo8vdTJcpFWeaUEKH3G6detaXv46HxtQcENwxGBbRqbfTCJ9BUnWP" + "CkE8WApKPJ4h7EAapnXCZq1a9AqWWzs1n31VdfwbrQk") assert pub.string() == expStr