<commit_before>let axios = require('axios');

describe("integration tests", function () {
  const TIMEOUT = 20*1000;
  this.timeout(TIMEOUT);
  this.slow(TIMEOUT/2);

  const HORIZON = 'https://horizon-testnet.stellar.org';
  StellarSdk.Network.useTestNetwork();
  let server = new StellarSdk.Server(HORIZON);
  let master = StellarSdk.Keypair.random();

  before(function(done) {
    axios.get(`${HORIZON}/friendbot?addr=${master.publicKey()}`).then(() => done());
  });

  after(function(done) {
    // Merge account
    server.operations().forAccount(master.publicKey()).limit(1).order('asc')
      .call()
      .then(response => {
        let operation = response.records[0];
        
        return server.loadAccount(master.publicKey())
          .then(source => {
            let tx = new StellarSdk.TransactionBuilder(source)
              .addOperation(StellarSdk.Operation.accountMerge({
                destination: operation.funder
              }))
              .build();

            tx.sign(master);

            server.submitTransaction(tx).then(() => done());
          });
      });
  });

  function createNewAccount(accountId) {
    return server.loadAccount(master.publicKey())
      .then(source => {
        let tx = new StellarSdk.TransactionBuilder(source)
          .addOperation(StellarSdk.Operation.createAccount({
            destination: accountId,
            startingBalance: "1"
          }))
          .build();

        tx.sign(master);

        return server.submitTransaction(tx);
      });
  }

  describe("/transaction", function () {
    it("submits a new transaction", function (done) {
      createNewAccount(StellarSdk.Keypair.random().publicKey())
        .then(result => {
          expect(result.ledger).to.be.not.null;
          done();
        })
        .catch(err => done(err));
    });

    it("submits a new transaction with error", function (done) {
      server.loadAccount(master.publicKey())
        .then(source => {
          source.incrementSequenceNumber(); // This will cause an error
          let tx = new StellarSdk.TransactionBuilder(source)
            .addOperation(StellarSdk.Operation.createAccount({
              destination: StellarSdk.Keypair.random().publicKey(),
              startingBalance: "1"
            }))
            .build();

          tx.sign(master);

          server.submitTransaction(tx)
            .then(result => done(new Error("This promise should be rejected.")))
            .catch(error => {
              expect(error.data.extras.result_codes.transaction).to.equal('tx_bad_seq');
              done();
            });
        });
    });
  });

  describe("/accounts", function () {
    it("get account", function (done) {
      server.accounts().accountId(master.publicKey())
        .call()<commit_msg>Fix test<commit_after>let axios = require('axios');

describe("integration tests", function () {
  const TIMEOUT = 20*1000;
  this.timeout(TIMEOUT);
  this.slow(TIMEOUT/2);

  const HORIZON = 'https://horizon-testnet.stellar.org';
  StellarSdk.Network.useTestNetwork();
  let server = new StellarSdk.Server(HORIZON);
  let master = StellarSdk.Keypair.random();

  before(function(done) {
    axios.get(`${HORIZON}/friendbot?addr=${master.publicKey()}`).then(() => done());
  });

  after(function(done) {
    // Merge account
    server.operations().forAccount(master.publicKey()).limit(1).order('asc')
      .call()
      .then(response => {
        let operation = response.records[0];
        
        return server.loadAccount(master.publicKey())
          .then(source => {
            let tx = new StellarSdk.TransactionBuilder(source)
              .addOperation(StellarSdk.Operation.accountMerge({
                destination: operation.funder
              }))
              .build();

            tx.sign(master);

            server.submitTransaction(tx).then(() => done());
          });
      });
  });

  function createNewAccount(accountId) {
    return server.loadAccount(master.publicKey())
      .then(source => {
        let tx = new StellarSdk.TransactionBuilder(source)
          .addOperation(StellarSdk.Operation.createAccount({
            destination: accountId,
            startingBalance: "1"
          }))
          .build();

        tx.sign(master);

        return server.submitTransaction(tx);
      });
  }

  describe("/transaction", function () {
    it("submits a new transaction", function (done) {
      createNewAccount(StellarSdk.Keypair.random().publicKey())
        .then(result => {
          expect(result.ledger).to.be.not.null;
          done();
        })
        .catch(err => done(err));
    });

    it("submits a new transaction with error", function (done) {
      server.loadAccount(master.publicKey())
        .then(source => {
          source.incrementSequenceNumber(); // This will cause an error
          let tx = new StellarSdk.TransactionBuilder(source)
            .addOperation(StellarSdk.Operation.createAccount({
              destination: StellarSdk.Keypair.random().publicKey(),
              startingBalance: "1"
            }))
            .build();

          tx.sign(master);

          server.submitTransaction(tx)
            .then(result => done(new Error("This promise should be rejected.")))
            .catch(error => {
              expect(error.response.data.extras.result_codes.transaction).to.equal('tx_bad_seq');
              done();
            });
        });
    });
  });

  describe("/accounts", function () {
    it("get account", function (done) {
      server.accounts().accountId(master.publicKey())
        .call()
{'fraction_non_alphanumeric': 0.14731029568934806, 'fraction_numerical': 0.003918774492340577, 'mean_word_length': 2.2893966022261276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '7534878', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1559, 'n_words': 252}