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
def test_already_signed_raise(self): # GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM source = Keypair.from_secret( "SCCS5ZBI7WVIJ4SW36WGOQQIWJYCL3VOAULSXX3FB57USIO25EDOYQHH") 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) network = Network.public_network() te = TransactionEnvelope(tx, network) assert binascii.hexlify(te.hash()).decode() == te.hash_hex() # te.sign(source) te.sign("SCCS5ZBI7WVIJ4SW36WGOQQIWJYCL3VOAULSXX3FB57USIO25EDOYQHH") hashx = bytes.fromhex( "94e8223a518ac16a8cb110ab1952ef14da2c10b264645c38c8b3d82bd2b20000") te.sign_hashx(hashx) with pytest.raises(SignatureExistError, match="The keypair has already signed."): te.sign(source) with pytest.raises(SignatureExistError, match="The preimage has already signed."): te.sign_hashx(hashx)
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
def test_to_xdr(self): # GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM source = Keypair.from_secret( "SCCS5ZBI7WVIJ4SW36WGOQQIWJYCL3VOAULSXX3FB57USIO25EDOYQHH") 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) network = Network.public_network() te = TransactionEnvelope(tx, network) assert binascii.hexlify(te.hash()).decode() == te.hash_hex() te.sign(source) hashx = bytes.fromhex( "94e8223a518ac16a8cb110ab1952ef14da2c10b264645c38c8b3d82bd2b20000") te.sign_hashx(hashx) te_xdr = "AAAAAMvXcdYjKhx0qxnsDsczxKuqa/65lZz6sjjHHczyh50JAAAAyAAAAAAAAAABAAAAAQAAAAAAADA5AAAAAAAA3dUAAAACAAAAAAAAAGQAAAACAAAAAAAAAAEAAAAA0pjFgVcRZZHpMgnpXHpb/xIbLh0/YYto0PzI7+Xl5HAAAAAAAAAAAlQL5AAAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAFd29ybGQAAAAAAAAAAAAAAvKHnQkAAABAM4dg0J1LEFBmbDESJ5d+60WCuZC8lnA80g45qyEgz2oRBSNw1mOfZETnL/BgrebkG/K03oI2Wqcs9lvDKrDGDE0sOBsAAAAglOgiOlGKwWqMsRCrGVLvFNosELJkZFw4yLPYK9KyAAA=" assert te.to_xdr() == te_xdr restore_te = TransactionEnvelope.from_xdr(te_xdr, network) assert restore_te.to_xdr() == te_xdr
def test_to_xdr(self, min_time, max_time, xdr): op_xdr_object = TimeBounds(min_time, max_time).to_xdr_object() assert op_xdr_object.to_xdr() == xdr from_instance = TimeBounds.from_xdr_object(op_xdr_object) assert isinstance(from_instance, TimeBounds) assert from_instance.max_time == max_time assert from_instance.min_time == min_time
def test_to_xdr_v1(self): # GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM source = Keypair.from_secret( "SCCS5ZBI7WVIJ4SW36WGOQQIWJYCL3VOAULSXX3FB57USIO25EDOYQHH") 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)] tx = Transaction(source, sequence, fee, ops, memo, time_bounds, True) te = TransactionEnvelope(tx, Network.PUBLIC_NETWORK_PASSPHRASE) assert binascii.hexlify(te.hash()).decode() == te.hash_hex() te.sign(source) te_xdr = "AAAAAgAAAADL13HWIyocdKsZ7A7HM8Srqmv+uZWc+rI4xx3M8oedCQAAAMgAAAAAAAAAAQAAAAEAAAAAAAAwOQAAAAAAAN3VAAAAAgAAAAAAAABkAAAAAQAAAAAAAAABAAAAANKYxYFXEWWR6TIJ6Vx6W/8SGy4dP2GLaND8yO/l5eRwAAAAAAAAAAJUC+QAAAAAAAAAAAHyh50JAAAAQCXOQnmno3he687bKRtDc6+BXRUf8t+RnTuHy+sKf35UjfFiQbIge+txehmg0N61JsFWfwbL0JtgOjzyeZw5JAs=" assert te.to_xdr() == te_xdr restore_te = TransactionEnvelope.from_xdr( te_xdr, Network.PUBLIC_NETWORK_PASSPHRASE) assert restore_te.to_xdr() == te_xdr
def test_to_xdr_v0(self): source = Keypair.from_public_key( "GC3GJU6L7V7ZLPLKG3NTMC6GYYKBMNNKCPP36FG3LWEVPOHUPY6QJIGL") destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2" amount = "1000.0" sequence = 2 memo = NoneMemo() fee = 200 asset = Asset.native() time_bounds = TimeBounds(12345, 56789) ops = [Payment(destination, asset, amount)] tx_object = Transaction(source, sequence, fee, ops, memo, time_bounds, False).to_xdr_object() restore_transaction = Transaction.from_xdr_object(tx_object, False) assert isinstance(restore_transaction, Transaction) assert restore_transaction.source == source.public_key assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds assert restore_transaction.sequence == sequence
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
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
def test_equals(self): assert TimeBounds(1, 2) == TimeBounds(1, 2) assert TimeBounds(1, 2) != TimeBounds(1, 0)
def test_to_xdr_with_invalid_time_raise(self, min_time, max_time, message): with pytest.raises(ValueError, match=message): TimeBounds(min_time, max_time)
def test_to_xdr_with_invalid_time_raise(self, min_time, max_time): with pytest.raises(ValueError, match="max_time must be >= min_time."): TimeBounds(min_time, max_time)