def test_valid_checksum(self): """Test checksum creation and validation.""" for test in VALID_CHECKSUM: hrp, _ = segwit_addr.bech32_decode(test) assert hrp is not None pos = test.rfind('1') test = test[:pos + 1] + chr(ord(test[pos + 1]) ^ 1) + test[pos + 2:] hrp, _ = segwit_addr.bech32_decode(test) assert hrp is None
def get_version(address): version, _ = bech32_decode(address) if version is None: version = b58decode_check(address)[:1] if (version in (MAIN_PUBKEY_HASH, MAIN_SCRIPT_HASH) or version in BECH32_MAIN_VERSION_SET): return 'main' elif (version in (TEST_PUBKEY_HASH, TEST_SCRIPT_HASH) or version in BECH32_TEST_VERSION_SET): return 'test' else: raise ValueError('{} does not correspond to a mainnet nor ' 'testnet address.'.format(version))
def test_invalid_checksum(self): """Test validation of invalid checksums.""" for test in INVALID_CHECKSUM: hrp, _ = segwit_addr.bech32_decode(test) assert hrp is None