def test_eth_account_prepared_encrypt(acct, private_key, password, kdf, iterations, expected_decrypted_key, expected_kdf): account = acct.privateKeyToAccount(private_key) if kdf is None: encrypted = account.encrypt(password, iterations=iterations) else: encrypted = account.encrypt(password, kdf=kdf, iterations=iterations) assert encrypted['address'] == '2c7536e3605d9c16a7a3d7b1898e529396a65c23' assert encrypted['version'] == 3 assert encrypted['crypto']['kdf'] == expected_kdf if iterations is None: expected_iterations = get_default_work_factor_for_kdf(expected_kdf) else: expected_iterations = iterations if expected_kdf == 'pbkdf2': assert encrypted['crypto']['kdfparams']['c'] == expected_iterations elif expected_kdf == 'scrypt': assert encrypted['crypto']['kdfparams']['n'] == expected_iterations else: raise Exception( "test must be upgraded to confirm iterations with kdf %s" % expected_kdf) decrypted_key = acct.decrypt(encrypted, password) assert isinstance(decrypted_key, HexBytes) assert decrypted_key == expected_decrypted_key
def test_eth_account_prepared_encrypt(acct, private_key, password, kdf, expected_decrypted_key, expected_kdf): account = acct.privateKeyToAccount(private_key) if kdf is None: encrypted = account.encrypt(password) else: encrypted = account.encrypt(password, kdf) assert encrypted['address'] == '2c7536e3605d9c16a7a3d7b1898e529396a65c23' assert encrypted['version'] == 3 assert encrypted['crypto']['kdf'] == expected_kdf decrypted_key = acct.decrypt(encrypted, password) assert isinstance(decrypted_key, HexBytes) assert decrypted_key == expected_decrypted_key