def test_testgiver_getaccount_address(self): t = TonlibClientFutures() ft = t.testgiver_getaccount_address() res = ft.result() self.assertIsInstance(res, dict) self.assertEqual(res['@type'], 'accountAddress') self.assertEqual(res['account_address'], 'Ef+BVndbeTJeXWLnQtm5bDC2UVpc0vH2TF2ksZPAPwcODSkb')
def test_testgiver_getaccount_address(self): t = TonlibClientFutures() ft = t.testgiver_getaccount_address() res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('accountAddress', res['@type']) self.assertEqual(self.testgiver_address, res['account_address'])
def test_raw_getaccount_state(self): t = TonlibClientFutures() ft = t.raw_get_account_state( '-1:DD74DD3DA6E2AC5A5A090875BD08D3F8E61388BD200AA7BBC70957640D732236' ) res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('raw.accountState', res['@type'])
def test_raw_send_boc(self): t = TonlibClientFutures() ft = t.raw_send_boc( 'B5EE9C724104020100000000A90001CF89FFBAE9BA7B4DC558B4B41210EB7A11A7F1CC27117A40154F778E12AEC81AE6446C003219C84E5B04B5AE35ACCF717469539F4AB34623CC3BA9C980E1F620487F0E29CC03FA0A68A6A53E78CB4DC877454AE9DD74561BDA8CFD95069E67632A91C070000000101C010078427FBE2D02C6134ABBBF7CEB0CF1B6ED7630E39606557084BB72836CFEADFA96163521DCD6500000000000000000000000000000000000005445535414557A60' ) res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('ok', res['@type'])
def test_raw_get_transactions(self): t = TonlibClientFutures() ft = t.raw_get_transactions( '-1:DD74DD3DA6E2AC5A5A090875BD08D3F8E61388BD200AA7BBC70957640D732236', '429475000001', '2AF9BC9B61CE16A99FCA33ED2025AC59C44475626A65AC65A9533384AFE7023B') res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('raw.transactions', res['@type'])
def test_raw_get_transactions(self): t = TonlibClientFutures() ft = t.raw_get_transactions( '-1:DD74DD3DA6E2AC5A5A090875BD08D3F8E61388BD200AA7BBC70957640D732236', '466495000001', '34A9E5FA0C3F3C4CCCE04013F6D80EE5EC4EC882C0DEF17FBC6C89DFD8E97B15') res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('raw.transactions', res['@type'])
class TestgiverTestCase(unittest.TestCase): keystore = os.path.join(proj_path, 'tmp') decrypt_password = '******' encrypted_public_key = 'Pub3Dt+JCpOPtuOqZHWLmsb7mIHU5JG3MHIcrojzQ/N5TmfL' encrypted_secret = 'JlzkJ2sOr9R38e0DzwRBBY1sYwwWWeCd2sUI+RyzH3A=' t = TonlibClientFutures(keystore=keystore) def _test_wallet_init(self): res_decrypt_key = self.t.decrypt_key( public_key=self.encrypted_public_key, secret=self.encrypted_secret, local_password=self.decrypt_password ).result() self.assertIsInstance(res_decrypt_key, dict) decrypted_public_key = res_decrypt_key['public_key'] decrypted_secret = res_decrypt_key['secret'] print(decrypted_public_key, decrypted_secret) decrypted_public_key = 'Pub3Dt+JCpOPtuOqZHWLmsb7mIHU5JG3MHIcrojzQ/N5TmfL' decrypted_secret = 'ApnH0qQfVfAgALjabbr6R7BxqsG4kNWTVOcTZEvHIWM=' res_wallet_init = self.t.wallet_init( public_key=decrypted_public_key, secret=decrypted_secret ).result() self.assertIsInstance(res_wallet_init, dict) self.assertEqual('ok', res_wallet_init['@type']) res_wallet_account_address = self.t.wallet_get_account_address( public_key=decrypted_public_key ).result() self.assertIsInstance(res_wallet_account_address, dict) self.assertEqual('accountAddress', res_wallet_account_address['@type']) account_address = res_wallet_account_address['account_address'] res_wallet_account_state = self.t.wallet_get_account_state( address=account_address ).result() self.assertIsInstance(res_wallet_account_state, dict) res_delete_decrypted_key = self.t.delete_key( public_key=decrypted_public_key, secret=decrypted_secret ).result() self.assertIsInstance(res_delete_decrypted_key, dict) self.assertNotEqual('error', res_delete_decrypted_key['@type'])
class KeyingPrimitivesTestCase(unittest.TestCase): keystore = os.path.join(proj_path, 'tmp') password = '******' salt = 'kiuthkiukhmvncbxgfsryturyitukGRETRTUYKYTFDH' PBKDF_ITERATIONS = 100000 t = TonlibClientFutures(keystore=keystore) def test_kdf_1(self): password = bytes(self.password, 'utf-8') salt = bytes(self.salt, 'utf-8') local_kdf = hashlib.pbkdf2_hmac('sha512', password, salt, self.PBKDF_ITERATIONS) local_kdf = base64.b64encode(local_kdf) remote_kdf_res = self.t.external_kdf( password=self.password, salt=self.salt, iterations=self.PBKDF_ITERATIONS).result() remote_kdf = bytes(remote_kdf_res['bytes'], 'utf-8') self.assertEqual(local_kdf, remote_kdf)
class TestgiverTestCase(unittest.TestCase): keystore = os.path.join(proj_path, 'tmp') vect = '23454927' * 5 local_password = '******' key_password = '******' mn = Mnemonic("english") mn_phrase = mn.to_mnemonic(unhexlify(vect)).split(' ') t = TonlibClientFutures(keystore=keystore) def test_testgiver_init(self): res_create_new_key = self.t.create_new_key( local_password=self.local_password, mnemonic=self.mn_phrase).result() res_decrypt_key = self.t.decrypt_key( public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret'], local_password=self.local_password).result() res_wallet_init = self.t.wallet_init( public_key=res_decrypt_key['public_key'], secret=res_decrypt_key['secret']).result() self.assertIsInstance(res_wallet_init, dict) self.assertEqual('ok', res_wallet_init['@type']) res_delete_new_key = self.t.delete_key( public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret']).result() self.assertIsInstance(res_delete_new_key, dict) self.assertNotEqual('error', res_delete_new_key['@type']) # don't forget to delete decrypted key too because there is no method to decrypt key only in memory res_delete_decrypted_key = self.t.delete_key( public_key=res_decrypt_key['public_key'], secret=res_decrypt_key['secret']).result() self.assertIsInstance(res_delete_decrypted_key, dict) self.assertNotEqual('error', res_delete_decrypted_key['@type']) def test_testgiver_address_new_transaction(self): """ Reference implementation of wallet operation using testgiver_ and test_wallet_ funcs. Due to asynchronous nature of TON the rest of test cannot be done at the moment of faucet exhaustion. Waiting for a new faucet address & and Grams on it :) """ # create key res_create_new_key = self.t.create_new_key( local_password=self.local_password, mnemonic=self.mn_phrase).result() self.assertIsInstance(res_create_new_key, dict) self.assertNotEqual('error', res_create_new_key['@type']) # decrypt key to public key & secret res_decrypt_key = self.t.decrypt_key( public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret'], local_password=self.local_password).result() self.assertIsInstance(res_create_new_key, dict) self.assertNotEqual('error', res_decrypt_key['@type']) # convert public key to account address (testing in 0 chain) res_wallet_account_address = self.t.wallet_get_account_address( public_key=res_decrypt_key['public_key']).result() self.assertIsInstance(res_wallet_account_address, dict) self.assertNotEqual('error', res_wallet_account_address['@type']) self.assertEqual('accountAddress', res_wallet_account_address['@type']) account_address = res_wallet_account_address['account_address'] # get current state of faucet (we need seq number) res_testgiver_account_state = self.t.testgiver_getaccount_state( ).result() self.assertIsInstance(res_testgiver_account_state, dict) self.assertEqual('testGiver.accountState', res_testgiver_account_state['@type']) # send grams from faucet to uninitialized wallet res_testgiver_send_grams = self.t.testgiver_send_grams( dest_address=account_address, seq_no=res_testgiver_account_state['seqno'], amount=int(1 * 10e8)).result() self.assertIsInstance(res_testgiver_send_grams, dict) self.assertNotEqual('error', res_testgiver_send_grams['@type']) self.assertEqual('sendGramsResult', res_testgiver_send_grams['@type']) # init new test wallet specified by public key & secret res_test_wallet_init = self.t.wallet_init( public_key=res_decrypt_key['public_key'], secret=res_decrypt_key['secret']).result() self.assertIsInstance(res_test_wallet_init, dict) self.assertNotEqual('error', res_test_wallet_init['@type']) self.assertEqual('ok', res_test_wallet_init['@type']) res_test_wallet_get_account_state = self.t.wallet_get_account_state( address=account_address).result() self.assertIsInstance(res_test_wallet_get_account_state, dict) # self.assertNotEqual('error', res_test_wallet_init['@type']) res_delete_new_key = self.t.delete_key( public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret']).result() self.assertIsInstance(res_delete_new_key, dict) self.assertNotEqual('error', res_delete_new_key['@type']) # don't forget to delete decrypted key too because there is no method to decrypt key only in memory res_delete_decrypted_key = self.t.delete_key( public_key=res_decrypt_key['public_key'], secret=res_decrypt_key['secret']).result() self.assertIsInstance(res_delete_decrypted_key, dict) self.assertNotEqual('error', res_delete_decrypted_key['@type'])
def test_testgiver_getaccount_state_parallel(self): t = TonlibClientFutures(threads=5) fts = [t.testgiver_getaccount_state() for _ in range(10)] ress = [f.result() for f in fts] [self.assertIsInstance(r, dict) for r in ress] [self.assertEqual('testGiver.accountState', r['@type']) for r in ress]
def test_testgiver_getaccount_state(self): t = TonlibClientFutures() ft = t.testgiver_getaccount_state() res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('testGiver.accountState', res['@type'])
class ClientKeyingTestCase(unittest.TestCase): keystore = os.path.join(proj_path, 'tmp') vect = '23454927' * 5 local_password = '******' key_password = '******' mn = Mnemonic("english") mn_phrase = mn.to_mnemonic(unhexlify(vect)).split(' ') t = TonlibClientFutures(keystore=keystore) def _create_new_key(self): ft = self.t.create_new_key(local_password=self.local_password, mnemonic=self.mn_phrase) res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('key', res['@type']) return res def _delete_key(self, public_key, secret): ft = self.t.delete_key(public_key=public_key, secret=secret) res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('ok', res['@type']) def test_create_new_key(self): res_create_new_key = self.t.create_new_key( local_password=self.local_password, mnemonic=self.mn_phrase).result() self.assertIsInstance(res_create_new_key, dict) self.assertEqual('key', res_create_new_key['@type']) self._delete_key(public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret']) def test_export_key(self): res_create_new_key = self._create_new_key() res_export_key = self.t.export_key( public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret'], local_password=self.local_password).result() self.assertIsInstance(res_export_key, dict) self.assertEqual('exportedKey', res_export_key['@type']) self._delete_key(public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret']) def _test_export_pem_key(self): res_create_new_key = self._create_new_key() res_export_pem_key = self.t.export_pem_key( public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret'], local_password=self.local_password, key_password=self.key_password).result() self.assertIsInstance(res_export_pem_key, dict) self.assertEqual('exportedKey', res_export_pem_key['@type']) self._delete_key(public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret']) def test_export_encrypted_key(self): res_create_new_key = self._create_new_key() res_export_encrypted_key = self.t.export_encrypted_key( public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret'], local_password=self.local_password, key_password=self.key_password).result() self.assertIsInstance(res_export_encrypted_key, dict) self.assertEqual('exportedEncryptedKey', res_export_encrypted_key['@type']) self._delete_key(public_key=res_create_new_key['public_key'], secret=res_create_new_key['secret']) def _test_import_key(self): res_import_key = self.t.import_key(local_password=self.local_password, mnemonic_password=self.key_password, mnemonic=self.mn_phrase).result() self.assertIsInstance(res_import_key, dict) self.assertEqual('key', res_import_key['@type']) self._delete_key(public_key=res_import_key['public_key'], secret=res_import_key['secret'])
def test_raw_get_masterchain_info(self): t = TonlibClientFutures() ft = t.raw_get_masterchain_info() res = ft.result() self.assertIsInstance(res, dict) self.assertEqual('raw.masterchainInfo', res['@type'])
from flask import Flask, request, jsonify from secrets import token_hex from ton_client.client import TonlibClientFutures app = Flask(__name__) ton = TonlibClientFutures() @app.route('/api/gen-key', methods=["POST"]) def gen_key(): seed = request.json['seed'] res = ton.create_new_key(seed) return jsonify(res.result()) @app.route('/api/get-account-state', methods=["POST"]) def get_account_state(): addr = request.json['address'] res = ton.raw_get_account_state(addr) return jsonify(res.result())