<commit_before># coding:utf-8
# For use with nosetests

import sys
sys.path.append('src')
sys.path.append('src/lib/stellar-sdk-py')

SOURCE = 'GDJVFDG5OCW5PYWHB64MGTHGFF57DRRJEDUEFDEL2SLNIOONHYJWHA3Z'
SEED = 'SAHPFH5CXKRMFDXEIHO6QATHJCX6PREBLCSFKYXTTCDDV6FJ3FXX4POT'
DESTINATION = 'GCW24FUIFPC2767SOU4JI3JEAXIHYJFIJLH7GBZ2AVCBVP32SJAI53F5'
SEQ_NUM = 1 # Remember to increment it
FEE = 100
AMOUNT= 10 * 10**6

def bip(envelope=False): # Base64-ip, like zip.
	assert envelope
	import base64
	from stellar_base.stellarxdr import StellarXDR_pack as Xdr
	x = Xdr.STELLARXDRPacker()
	x.pack_TransactionEnvelope(envelope.to_xdr_object())
	return base64.b64encode(x.get_buffer())

def do_single_signer(operation_opts=False, tx_opts=False):
	assert operation_opts and tx_opts
	from stellar_base.operation import Payment
	from stellar_base.transaction import Transaction
	from stellar_base.keypair import Keypair
	from stellar_base.transaction_envelope import TransactionEnvelope as Te

	operation = Payment( opts=operation_opts)
	tx = Transaction( source=SOURCE, opts=tx_opts)
	tx.add_operation( operation=operation )
	envelope = Te( tx=tx, opts={"network_id": "TESTNET"} )
	signer = Keypair.from_seed( seed=SEED )
	envelope.sign( keypair=signer )
	envelope_b64 = bip(envelope)

	print(envelope_b64)
	return envelope_b64

def setup_module(module):
	pass

def teardown_module(module):
	pass

def my_setup_function():
	pass
 
def my_teardown_function():
	pass

def test_load_module():
	import stellar_base
	return True

def test_minimal_defaults():
	from stellar_base.asset import Asset

	result = b'<KEY>
	assert(result == do_single_signer(
		operation_opts={
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		},
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))

def test_minimal_placeholders():
	from stellar_base.asset import Asset
	from stellar_base.memo import NoneMemo

	result = b'<KEY>
	assert(result == do_single_signer(
		operation_opts={
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		},
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_short_asset():
	from stellar_base.asset import Asset
	from stellar_base.memo import NoneMemo

	result = b'<KEY>

	assert(result == do_single_signer(
		operation_opts={
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset('USD4', SOURCE),
			'amount': AMOUNT,
		},
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_long_asset():
	from stellar_base.asset import Asset
	from stellar_base.memo import NoneMemo

	result = b'<KEY>
	assert(result == do_single_signer(
		operation_opts={
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset('SNACKS789ABC', SOURCE),
			'amount': AMOUNT,
		},
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_textMemo_ascii():
	from stellar_base.asset import Asset
	from stellar_base.memo import TextMemo

	result = b'<KEY>
	assert(result == do_single_signer(
		operation_opts={
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		},
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': TextMemo('testing'),
			'fee': FEE,
		},
	))

def test_textMemo_unicode():
	from stellar_base.asset import Asset
	from stellar_base.memo import TextMemo

	result = b'<KEY>
	assert(result == do_single_signer(
		operation_opts={
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		},
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': TextMemo('tēštīņģ'),
			'fee': FEE,
		},
	))<commit_msg>Add tests for every Op<commit_after># coding:utf-8
# For use with nosetests

import base64

from stellar_base.memo import *
from stellar_base.operation import *
from stellar_base.transaction import Transaction
from stellar_base.keypair import Keypair
from stellar_base.transaction_envelope import TransactionEnvelope as Te
from stellar_base.asset import Asset

SOURCE = 'GDJVFDG5OCW5PYWHB64MGTHGFF57DRRJEDUEFDEL2SLNIOONHYJWHA3Z'
SEED = 'SAHPFH5CXKRMFDXEIHO6QATHJCX6PREBLCSFKYXTTCDDV6FJ3FXX4POT'
DESTINATION = 'GCW24FUIFPC2767SOU4JI3JEAXIHYJFIJLH7GBZ2AVCBVP32SJAI53F5'
SEQ_NUM = 1
FEE = 100
AMOUNT= 10 * 10**6

def bip(envelope=False): # Base64-ip, like zip.
	assert envelope
	from stellar_base.stellarxdr import StellarXDR_pack as Xdr
	x = Xdr.STELLARXDRPacker()
	x.pack_TransactionEnvelope(envelope.to_xdr_object())
	return base64.b64encode(x.get_buffer())
def do_single_signer(op, tx_opts):

	tx = Transaction( source=SOURCE, opts=tx_opts)
	tx.add_operation( operation=op )
	envelope = Te( tx=tx, opts={"network_id": "TESTNET"} )
	signer = Keypair.from_seed( seed=SEED )
	envelope.sign( keypair=signer )
	envelope_b64 = bip(envelope)

	print(envelope_b64)
	return envelope_b64

def setup_module(module):
	pass
def teardown_module(module):
	pass
def my_setup_function():
	pass
def my_teardown_function():
	pass

def test_load_module():
	return True

def test_op_createAccount_minimal_defaults():
	result = b'AAAAANNSjN1wrdfixw+<KEY>'
	assert(result == do_single_signer(
		op=CreateAccount({
			'destination': DESTINATION,
			'starting_balance': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))
def test_op_createAccount_minimal_placeholders():
	result = b'<KEY>'
	assert(result == do_single_signer(
		op=CreateAccount({
			'destination': DESTINATION,
			'starting_balance': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))	

def test_op_payment_minimal_defaults():
	result = b'<KEY>
	assert(result == do_single_signer(
		op=Payment({
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))
def test_op_payment_minimal_placeholders():
	result = b'<KEY>
	assert(result == do_single_signer(
		op=Payment({
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))
def test_op_payment_short_asset():
	result = b'<KEY>
	assert(result == do_single_signer(
		op=Payment({
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset('USD4', SOURCE),
			'amount': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))
def test_op_payment_long_asset():
	result = b'AAAAANNSjN1wrdfixw+4w0zmKXvxxikg6EKMi9SW1DnNPhNjAAAAZAAAAAAAAAACAAAAAAAAAAAAAAABAAAAAQAAAADTUozdcK3X4scPuMNM5il78cYpIOhCjIvUltQ5zT4TYwAAAAEAAAAAra4WiCvFr/vydTiUbSQF0HwkqErP8wc6BUQav3qSQI4AAAACU05BQ0tTNzg5QUJDAAAAANNSjN1wrdfixw+4w0zmKXvxxikg6EKMi9SW1DnNPhNjAAAAAACYloAAAAAAAAAAAc0+E2MAAABAE+vwbVK5XVhw3z8qqKW0P6HL7zZdgOSjSl6DVWQicmp2a0un8evaCUDXexCXxUx+UBf/HlowHJdLaXFKmRy5AQ=='
	assert(result == do_single_signer(
		op=Payment({
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset('SNACKS789ABC', SOURCE),
			'amount': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))
def test_op_payment_textMemo_ascii():
	result = b'<KEY>
	assert(result == do_single_signer(
		op=Payment({
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': TextMemo('testing'),
			'fee': FEE,
		},
	))
def test_op_payment_textMemo_unicode():
	result = b'<KEY>
	assert(result == do_single_signer(
		op=Payment({
			'source': SOURCE,
			'destination': DESTINATION,
			'asset': Asset.native(),
			'amount': AMOUNT,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': TextMemo('tēštīņģ'),
			'fee': FEE,
		},
	))

def test_op_pathPayment_min_defaults():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=PathPayment({
			'source': SOURCE,
			'destination': DESTINATION,
			'send_asset': Asset.native(),
			'dest_asset': Asset.native(),
			'send_max': AMOUNT,
			'dest_amount': AMOUNT,
			'path': [],
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))
def test_op_pathPayment_min_placeholders():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=PathPayment({
			'source': SOURCE,
			'destination': DESTINATION,
			'send_asset': Asset.native(),
			'dest_asset': Asset.native(),
			'send_max': AMOUNT,
			'dest_amount': AMOUNT,
			'path': [],
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_op_manageOffer_min_defaults():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=ManageOffer({
			'selling': Asset('beer', SOURCE),
			'buying': Asset('beer', DESTINATION),
			'amount': 100,
			'n': 9,
			'd': 8,
			'offerId': 1,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))
def test_op_manageOffer_min_placeholders():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=ManageOffer({
			'selling': Asset('beer', SOURCE),
			'buying': Asset('beer', DESTINATION),
			'amount': 100,
			'n': 9,
			'd': 8,
			'offerId': 1,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_op_createPassiveOffer_min_defaults():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=CreatePassiveOffer({
			'selling': Asset('beer', SOURCE),
			'buying': Asset('beer', DESTINATION),
			'amount': 100,
			'n': 9,
			'd': 8,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))
def test_op_createPassiveOffer_min_placeholders():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=CreatePassiveOffer({
			'selling': Asset('beer', SOURCE),
			'buying': Asset('beer', DESTINATION),
			'amount': 100,
			'n': 9,
			'd': 8,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_op_SetOptions_empty_defaults():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=SetOptions({
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))
def test_op_SetOptions_emptly_placeholders():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=SetOptions({
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_op_changeTrust_min_defaults():
	result = b'<KEY>
	assert(result == do_single_signer(
		op=ChangeTrust({
			'asset': Asset('beer', DESTINATION),
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))
def test_op_changeTrust_min_placeholders():
	result = b'<KEY>
	assert(result == do_single_signer(
		op=ChangeTrust({
			'asset': Asset('beer', DESTINATION),
			'amount': 100,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_op_allowTrust_min_defaults():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=AllowTrust({
			'trustor': DESTINATION,
			'asset_code': 'beer',
			'authorize': True,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
		},
	))
def test_op_allowTrust_min_placeholders():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=AllowTrust({
			'trustor': DESTINATION,
			'asset_code': 'beer',
			'authorize': True,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))

def test_op_accountMerge_min_defaults():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=AccountMerge({
			'destination': DESTINATION,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))
def test_op_accountMerge_min_placeholders():
	result = b'' # TODO
	assert(result == do_single_signer(
		op=AccountMerge({
			'destination': DESTINATION,
		}),
		tx_opts={
			'seqNum': SEQ_NUM,
			'timeBounds': [],
			'memo': NoneMemo(),
			'fee': FEE,
		},
	))
{'fraction_non_alphanumeric': 0.15348140753681058, 'fraction_numerical': 0.015140171366774811, 'mean_word_length': 4.692234848484849, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2182880', 'n_tokens_mistral': 5556, 'n_tokens_neox': 4848, 'n_words': 867}