def test_encode_muxed_account_ed25519(self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" data = Xdr.types.MuxedAccount( type=Xdr.const.KEY_TYPE_ED25519, ed25519=StrKey.decode_ed25519_public_key(account_id), ) encoded = StrKey.encode_muxed_account(data) assert encoded == StrKey.encode_ed25519_public_key( StrKey.decode_ed25519_public_key(account_id))
def test_decode_muxed_account_ed25519(self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" # account_id_id = 1234 # account_id_muxed = "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" decoded = StrKey.decode_muxed_account(account_id) assert (decoded.to_xdr() == Xdr.types.MuxedAccount( type=Xdr.const.KEY_TYPE_ED25519, ed25519=StrKey.decode_ed25519_public_key(account_id), ).to_xdr())
def test_encode_muxed_account_med25519(self): data = Xdr.types.MuxedAccount.from_xdr( "AAABAAAAAAAAAATSIAB1furlg/xQ3Wafl2c6zCXsclgjrHP69sffMa0x5Qk=") expected = ( "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" ) assert StrKey.encode_muxed_account(data) == expected
def test_decode_muxed_account_med25519(self): # account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" # account_id_id = 1234 account_id_muxed = ( "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" ) decoded = StrKey.decode_muxed_account(account_id_muxed).to_xdr() assert decoded == "AAABAAAAAAAAAATSIAB1furlg/xQ3Wafl2c6zCXsclgjrHP69sffMa0x5Qk="
def test_parse_ed25519_account_id_from_muxed_account_xdr_object_ed25519( self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" muxed = Xdr.types.MuxedAccount( type=Xdr.const.KEY_TYPE_ED25519, ed25519=StrKey.decode_ed25519_public_key(account_id), ) assert (parse_ed25519_account_id_from_muxed_account_xdr_object(muxed) == account_id)
def test_parse_ed25519_account_id_from_muxed_account_xdr_object_muxed_account( self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" med25519 = Xdr.nullclass() med25519.ed25519 = StrKey.decode_ed25519_public_key(account_id) med25519.id = 1234 muxed = Xdr.types.MuxedAccount(type=Xdr.const.KEY_TYPE_MUXED_ED25519, med25519=med25519) assert (parse_ed25519_account_id_from_muxed_account_xdr_object(muxed) == account_id)
def test_parse_ed25519_account_id_from_muxed_account_xdr_object_ed25519( self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" muxed = stellar_xdr.MuxedAccount( type=stellar_xdr.CryptoKeyType.KEY_TYPE_ED25519, ed25519=stellar_xdr.Uint256( StrKey.decode_ed25519_public_key(account_id)), ) assert (parse_ed25519_account_id_from_muxed_account_xdr_object(muxed) == account_id)
def test_init_without_account_id_id(self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" account_id_id = None muxed_account_xdr = Xdr.types.MuxedAccount( type=Xdr.const.KEY_TYPE_ED25519, ed25519=StrKey.decode_ed25519_public_key(account_id), ) muxed_account = MuxedAccount(account_id, account_id_id) assert muxed_account.account_id_muxed is None assert muxed_account.to_xdr_object().to_xdr() == muxed_account_xdr.to_xdr() assert MuxedAccount.from_xdr_object(muxed_account_xdr) == muxed_account
def test_parse_ed25519_account_id_from_muxed_account_xdr_object_muxed_account( self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" ed25519 = StrKey.decode_ed25519_public_key(account_id) id = 1234 med25519 = stellar_xdr.MuxedAccountMed25519( id=stellar_xdr.Uint64(id), ed25519=stellar_xdr.Uint256(ed25519)) muxed = stellar_xdr.MuxedAccount( type=stellar_xdr.CryptoKeyType.KEY_TYPE_MUXED_ED25519, med25519=med25519) assert (parse_ed25519_account_id_from_muxed_account_xdr_object(muxed) == account_id)
def test_init_with_account_id_id(self): account_id = "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY" account_id_id = 1234 account_id_muxed = ( "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" ) med25519 = Xdr.nullclass() med25519.id = account_id_id med25519.ed25519 = StrKey.decode_ed25519_public_key(account_id) muxed_account_xdr = Xdr.types.MuxedAccount( type=Xdr.const.KEY_TYPE_MUXED_ED25519, med25519=med25519 ) muxed_account = MuxedAccount(account_id, account_id_id) assert muxed_account.account_id_muxed == account_id_muxed assert muxed_account.to_xdr_object().to_xdr() == muxed_account_xdr.to_xdr() assert MuxedAccount.from_xdr_object(muxed_account_xdr) == muxed_account
def test_set_options_ed25519_signer(): tx = make_default_tx() signer = "GAXN7HZQTHIPW7N2HGPAXMR42LPJ5VLYXMCCOX4D3JC4CQZGID3UYUPF" weight = 10 operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = (tx.append_ed25519_public_key_signer( account_id=signer, weight=weight, source=operation_source).build()) tx, operations = stellar.from_envelope(envelope) assert len(operations) == 1 assert isinstance(operations[0], messages.StellarSetOptionsOp) assert operations[0].source_account == operation_source assert operations[0].inflation_destination_account is None assert operations[0].clear_flags is None assert operations[0].set_flags is None assert operations[0].master_weight is None assert operations[0].low_threshold is None assert operations[0].medium_threshold is None assert operations[0].high_threshold is None assert operations[0].home_domain is None assert operations[0].signer_type == messages.StellarSignerType.ACCOUNT assert operations[0].signer_key == StrKey.decode_ed25519_public_key(signer) assert operations[0].signer_weight == weight
def test_decode_invalid_muxed_account_raise(self, key): with pytest.raises(ValueError): StrKey.decode_muxed_account(key)
def test_create_random(self): kp = Keypair.random() public_key = kp.public_key secret = kp.secret assert StrKey.is_valid_ed25519_public_key(public_key) assert StrKey.is_valid_ed25519_secret_seed(secret)