Пример #1
0
 def test_tx_fee_less_than_base_fee(self):
     inner_keypair = Keypair.from_secret(
         "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E")
     inner_source = Account(inner_keypair.public_key, 7)
     destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"
     amount = "2000.0000000"
     inner_tx = (TransactionBuilder(inner_source,
                                    Network.TESTNET_NETWORK_PASSPHRASE,
                                    50,
                                    v1=True).append_payment_op(
                                        destination=destination,
                                        amount=amount,
                                        asset_code="PMN").add_time_bounds(
                                            0, 0).build())
     inner_tx.sign(inner_keypair)
     fee_source = Keypair.from_secret(
         "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V")
     base_fee = 60
     with pytest.raises(
             ValueError,
             match="Invalid `base_fee`, it should be at least 100 stroops.",
     ):
         TransactionBuilder.build_fee_bump_transaction(
             fee_source.public_key,
             base_fee,
             inner_tx,
             Network.TESTNET_NETWORK_PASSPHRASE,
         )
 async def test_check_memo_required_with_fee_bump_transaction_async(
         self, httpserver):
     self.__inject_mock_server(httpserver)
     horizon_url = httpserver.url_for("/")
     keypair = Keypair.from_secret(
         "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY")
     account = Account(keypair.public_key, 1)
     async with Server(horizon_url, AiohttpClient()) as server:
         transaction = (TransactionBuilder(
             account, v1=True).append_payment_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_A, "10", "PMN"
             ).append_path_payment_strict_send_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C,
                 "PMN",
                 None,
                 "10",
                 "BTC",
                 "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2",
                 "1",
                 [],
             ).append_account_merge_op(
                 self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D).add_text_memo(
                     "hello, world").build())
         transaction.sign(keypair)
         fee_bump_tx = TransactionBuilder.build_fee_bump_transaction(
             fee_source=Keypair.random().public_key,
             base_fee=200,
             inner_transaction_envelope=transaction,
             network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
         )
         await server.submit_transaction(fee_bump_tx)
Пример #3
0
    def test_to_source_muxed_xdr(self):
        inner_keypair = Keypair.from_secret(
            "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E")
        inner_source = Account(inner_keypair.public_key, 7)
        destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"
        amount = "2000.0000000"
        inner_tx = (TransactionBuilder(inner_source,
                                       Network.TESTNET_NETWORK_PASSPHRASE,
                                       200,
                                       v1=True).append_payment_op(
                                           destination=destination,
                                           amount=amount,
                                           asset_code="PMN").add_time_bounds(
                                               0, 0).build())
        inner_tx.sign(inner_keypair)
        fee_source = Keypair.from_secret(
            "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V")
        fee_source2 = Keypair.from_secret(
            "SCVFDAOOXWR5TSPZF5U2MIE6V7M4LTOCNCD624Q6AEVBZ2XMH7HOWFZL")
        base_fee = 200
        fee_bump_tx = TransactionBuilder.build_fee_bump_transaction(
            fee_source.public_key,
            base_fee,
            inner_tx,
            Network.TESTNET_NETWORK_PASSPHRASE,
        )
        fee_bump_tx.sign(fee_source)
        xdr = "AAAABQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAGQAAAAAgAAAAAcVPE+R/n1VnbIrAK3tu5yVfTkhkqVz04ShWk2SrF3wAAAAMgAAAAAAAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAAEqBfIAAAAAAAAAAABSrF3wAAAAEAordQh63kT50muRLVYaWW7Pgtt8i1tc4t9Bv9MWFWFN3WfTHSU2Jxv7hedjZEyfBPvaS/XnwvYJFcHgPDd1JkNAAAAAAAAAAHov5sSAAAAQKu/RuArXn/P13IIJ8WlnVDStwOquXM0CsWzA4ooZY6gqJ3k1EfmMVIJ0cir0bMTJD9r+g2IUZCANU7wdC38PA0="

        assert fee_bump_tx.to_xdr() == xdr
        restore_te = FeeBumpTransactionEnvelope.from_xdr(
            xdr, Network.TESTNET_NETWORK_PASSPHRASE)
        assert restore_te == fee_bump_tx
        assert restore_te.transaction == fee_bump_tx.transaction
        assert restore_te.transaction == FeeBumpTransaction.from_xdr(
            fee_bump_tx.transaction.to_xdr_object().to_xdr(),
            Network.TESTNET_NETWORK_PASSPHRASE,
        )
        assert (restore_te.to_xdr() == TransactionBuilder.from_xdr(
            xdr, Network.TESTNET_NETWORK_PASSPHRASE).to_xdr())
        assert (restore_te.transaction._fee_source_muxed.to_xdr() ==
                fee_source.xdr_muxed_account().to_xdr())
        restore_te.transaction.fee_source = fee_source2.public_key
        assert restore_te.transaction.fee_source.public_key == fee_source2.public_key
        assert restore_te.transaction._fee_source_muxed is None
inner_source_keypair = Keypair.from_secret(
    "SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L")
destination_address = "GBVKI23OQZCANDUZ2SI7XU7W6ICYKYT74JBXDD2CYRDAFZHZNRPASSQK"

server = Server(horizon_url=horizon_url)
inner_account = server.load_account(inner_source_keypair)

inner_tx = (TransactionBuilder(source_account=inner_account,
                               network_passphrase=network_passphrase,
                               base_fee=50,
                               v1=True).append_payment_op(
                                   destination=destination_address,
                                   amount="100",
                                   asset_code="PMN").build())
inner_tx.sign(inner_source_keypair)

try:
    # This transaction will fail.
    tx_insufficient_fee_resp = server.submit_transaction(inner_tx)
except BadRequestError as e:
    print(e)

fee_bump_tx = TransactionBuilder.build_fee_bump_transaction(
    fee_source=fee_source_keypair,
    base_fee=200,
    inner_transaction_envelope=inner_tx,
    network_passphrase=network_passphrase)
fee_bump_tx.sign(fee_source_keypair)
response = server.submit_transaction(fee_bump_tx)
pprint.pprint(response)