コード例 #1
0
    def test_to_xdr_str_source_muxed_v1(self):
        source = "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ"
        source2 = "GDL635DMMORJHKEHHQIIB4VPYM6YGEMPLORYHHM2DEHAUOUXLSTMHQDV"
        destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2"
        amount = "1000.0"
        sequence = 1
        memo = IdMemo(100)
        fee = 200
        asset = Asset.native()
        time_bounds = TimeBounds(12345, 56789)
        ops = [
            Payment(destination, asset, amount),
            ManageData("hello", "world")
        ]

        tx = Transaction(source, sequence, fee, ops, memo, time_bounds, True)
        tx_object = tx.to_xdr_object()
        restore_tx = Transaction.from_xdr_object(tx_object, v1=True)
        assert restore_tx.to_xdr_object().to_xdr() == tx_object.to_xdr()
        assert restore_tx.source == Keypair.from_public_key(source)
        assert (restore_tx._source_muxed.to_xdr() == Keypair.from_public_key(
            source).xdr_muxed_account().to_xdr())
        assert restore_tx == tx
        restore_tx.source = source2
        assert restore_tx.source == Keypair.from_public_key(source2)
        assert restore_tx._source_muxed is None
        assert restore_tx != tx
コード例 #2
0
    def test_to_xdr_str_source(self):
        source = "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ"
        destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2"
        amount = "1000.0"
        sequence = 1
        memo = IdMemo(100)
        fee = 200
        asset = Asset.native()
        time_bounds = TimeBounds(12345, 56789)
        ops = [Payment(destination, asset, amount), ManageData("hello", "world")]

        tx_object = Transaction(
            source, sequence, fee, ops, memo, time_bounds
        ).to_xdr_object()
        assert (
            tx_object.to_xdr()
            == "AAAAAImbKEDtVjbFbdxfFLI5dfefG6I4jSaU5MVuzd3JYOXvAAAAyAAAAAAAAAABAAAAAQAAAAAAADA5AAAAAAAA3dUAAAACAAAAAAAAAGQAAAACAAAAAAAAAAEAAAAA0pjFgVcRZZHpMgnpXHpb/xIbLh0/YYto0PzI7+Xl5HAAAAAAAAAAAlQL5AAAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAFd29ybGQAAAAAAAAA"
        )

        restore_transaction = Transaction.from_xdr_object(tx_object)
        assert isinstance(restore_transaction, Transaction)
        assert restore_transaction.source == Keypair.from_public_key(source)
        assert restore_transaction.fee == fee
        assert restore_transaction.memo == memo
        assert restore_transaction.time_bounds == time_bounds
        assert restore_transaction.sequence == sequence
コード例 #3
0
ファイル: utils.py プロジェクト: jontsai/django-polaris
def make_memo(memo: str, memo_type: str) -> Optional[Memo]:
    if not memo:
        return None
    if memo_type == Transaction.MEMO_TYPES.id:
        return IdMemo(int(memo))
    elif memo_type == Transaction.MEMO_TYPES.hash:
        return HashMemo(memo_base64_to_hex(memo))
    elif memo_type == Transaction.MEMO_TYPES.text:
        return TextMemo(memo)
    else:
        raise ValueError()
コード例 #4
0
    def test_add_memo(self):
        source = Account("GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM", 1)
        builder = TransactionBuilder(
            source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
        ).add_id_memo(100)
        assert builder.memo == IdMemo(100)

        memo_hash = os.urandom(32)
        builder = TransactionBuilder(
            source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
        ).add_hash_memo(memo_hash)
        assert builder.memo == HashMemo(memo_hash)
        builder = TransactionBuilder(
            source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150
        ).add_return_hash_memo(memo_hash)
        assert builder.memo == ReturnHashMemo(memo_hash)
コード例 #5
0
    def test_to_xdr_str_muxed_account_str_source_v1(self):
        source = "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY"
        destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2"
        amount = "1000.0"
        sequence = 1
        memo = IdMemo(100)
        fee = 200
        asset = Asset.native()
        time_bounds = TimeBounds(12345, 56789)
        ops = [
            Payment(destination, asset, amount),
            ManageData("hello", "world")
        ]

        tx_object = Transaction(source, sequence, fee, ops, memo, time_bounds,
                                True).to_xdr_object()
        restore_transaction = Transaction.from_xdr(tx_object.to_xdr(), True)
        assert isinstance(restore_transaction, Transaction)
        assert restore_transaction.source == MuxedAccount.from_account(source)
        assert restore_transaction.fee == fee
        assert restore_transaction.memo == memo
        assert restore_transaction.time_bounds == time_bounds
        assert restore_transaction.sequence == sequence
コード例 #6
0
    def test_to_xdr_str_muxed_account_source_v1(self):
        source = MuxedAccount(
            "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234)
        destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2"
        amount = "1000.0"
        sequence = 1
        memo = IdMemo(100)
        fee = 200
        asset = Asset.native()
        time_bounds = TimeBounds(12345, 56789)
        ops = [
            Payment(destination, asset, amount),
            ManageData("hello", "world")
        ]

        tx_object = Transaction(source, sequence, fee, ops, memo, time_bounds,
                                True).to_xdr_object()
        restore_transaction = Transaction.from_xdr(tx_object.to_xdr(), True)
        assert isinstance(restore_transaction, Transaction)
        assert restore_transaction.source == source
        assert restore_transaction.fee == fee
        assert restore_transaction.memo == memo
        assert restore_transaction.time_bounds == time_bounds
        assert restore_transaction.sequence == sequence
コード例 #7
0
def test_memo_str_id_memo():
    assert utils.memo_str(IdMemo(123)) == ("123", Transaction.MEMO_TYPES.id)