<commit_before>var vmEnvironmentalInfoTest = require('../../../../tests/vmtests/vmEnvironmentalInfoTest.json'),
  async = require('async'),
  VM = require('../../../lib/vm'),
  Account = require('../../../lib/account.js'),
  assert = require('assert'),
  levelup = require('levelup'),
  testUtils = require('../../testUtils'),
  rlp = require('rlp'),
  Trie = require('merkle-patricia-tree');

var stateDB = levelup('', {
      db: require('memdown')
  });

describe('[Common]: vmEnvironmentalInfoTest', function () {
  var tests = Object.keys(vmEnvironmentalInfoTest);
  tests.forEach(function(testKey) {
    var state = new Trie(stateDB);
    var testData = vmEnvironmentalInfoTest[testKey];

    it(testKey + ' setup the pre', function (done) {
      testUtils.setupPreConditions(state, testData, done);
    });

    it(testKey + ' run code', function(done) {
      var env = testData.env,
        block = testUtils.makeBlockFromEnv(env),
        acctData,
        account,
        runCodeData,
        vm = new VM(state);

      acctData = testData.pre[testData.exec.address];
      account = new Account();
      account.nonce = testUtils.fromDecimal(acctData.nonce);
      account.balance = testUtils.fromDecimal(acctData.balance);

      runCodeData = testUtils.makeRunCodeData(testData.exec, account, block);
      vm.runCode(runCodeData, function(err, results) {
        assert(!err);

        // validate the postcondition of account
        acctData = testData.post[testData.exec.address];
        account = results.account;
        assert(testUtils.toDecimal(account.balance) === acctData.balance);
        assert(testUtils.toDecimal(account.nonce) === acctData.nonce);

        // validate the postcondition of other accounts
        delete testData.post[testData.exec.address];
        var keysOfPost = Object.keys(testData.post);
        async.each(keysOfPost, function(key, callback) {
          acctData = testData.post[key];

          state.get(new Buffer(key, 'hex'), function(err, raw) {
            assert(!err);

            account = new Account(raw);
            assert(testUtils.toDecimal(account.balance) === acctData.balance);
            assert(testUtils.toDecimal(account.nonce) === acctData.nonce);

            // validate storage
            var storageKeys = Object.keys(acctData.storage);
            if (storageKeys.length > 0) {
              state.root = account.stateRoot.toString('hex');
              storageKeys.forEach(function(skey) {
                state.get(testUtils.address(skey), function(err, data) {
                  assert(!err);
                  assert(rlp.decode(data).toString('hex') === acctData.storage[skey].slice(2));
                  callback();
                });
              });
            } else {
              callback();
            }
          });
        }, done);
      });
    });
  });

});<commit_msg>setting up balance1 test<commit_after>var vmEnvironmentalInfoTest = require('../../../../tests/vmtests/vmEnvironmentalInfoTest.json'),
  async = require('async'),
  VM = require('../../../lib/vm'),
  Account = require('../../../lib/account.js'),
  assert = require('assert'),
  levelup = require('levelup'),
  testUtils = require('../../testUtils'),
  rlp = require('rlp'),
  Trie = require('merkle-patricia-tree');

describe('[Common]: vmEnvironmentalInfoTest', function () {
  // this test needs to use runCall, since balances are only updated in runCall
  var balance1test = vmEnvironmentalInfoTest.balance1;
  delete vmEnvironmentalInfoTest.balance1;

  var tests = Object.keys(vmEnvironmentalInfoTest);
  tests.forEach(function(testKey) {
    var state = new Trie();
    var testData = vmEnvironmentalInfoTest[testKey];

    it(testKey + ' setup the pre', function (done) {
      testUtils.setupPreConditions(state, testData, done);
    });

    it(testKey + ' run code', function(done) {
      var env = testData.env,
        block = testUtils.makeBlockFromEnv(env),
        acctData,
        account,
        runCodeData,
        vm = new VM(state);

      acctData = testData.pre[testData.exec.address];
      account = new Account();
      account.nonce = testUtils.fromDecimal(acctData.nonce);
      account.balance = testUtils.fromDecimal(acctData.balance);

      runCodeData = testUtils.makeRunCodeData(testData.exec, account, block);
      vm.runCode(runCodeData, function(err, results) {
        assert(!err);

        // validate the postcondition of account
        acctData = testData.post[testData.exec.address];
        account = results.account;
        assert(testUtils.toDecimal(account.balance) === acctData.balance);
        assert(testUtils.toDecimal(account.nonce) === acctData.nonce);

        // validate the postcondition of other accounts
        delete testData.post[testData.exec.address];
        var keysOfPost = Object.keys(testData.post);
        async.each(keysOfPost, function(key, callback) {
          acctData = testData.post[key];

          state.get(new Buffer(key, 'hex'), function(err, raw) {
            assert(!err);

            account = new Account(raw);
            assert(testUtils.toDecimal(account.balance) === acctData.balance);
            assert(testUtils.toDecimal(account.nonce) === acctData.nonce);

            // validate storage
            var storageKeys = Object.keys(acctData.storage);
            if (storageKeys.length > 0) {
              state.root = account.stateRoot.toString('hex');
              storageKeys.forEach(function(skey) {
                state.get(testUtils.address(skey), function(err, data) {
                  assert(!err);
                  assert(rlp.decode(data).toString('hex') === acctData.storage[skey].slice(2));
                  callback();
                });
              });
            } else {
              callback();
            }
          });
        }, done);
      });
    });
  });

  describe('balance1 test', function() {
    var state = new Trie();
    var testData = balance1test;

    it('setup the pre', function (done) {
      testUtils.setupPreConditions(state, testData, done);
    });

    it('run code', function(done) {
      var env = testData.env,
        block = testUtils.makeBlockFromEnv(env),
        acctData,
        account,
        runCodeData,
        vm = new VM(state);

      acctData = testData.pre[testData.exec.address];
      account = new Account();
      account.nonce = testUtils.fromDecimal(acctData.nonce);
      account.balance = testUtils.fromDecimal(acctData.balance);

      runCodeData = testUtils.makeRunCodeData(testData.exec, account, block);
      vm.runCode(runCodeData, function(err, results) {
        assert(!err);

        // validate the postcondition of account
        acctData = testData.post[testData.exec.address];
        account = results.account;
        assert(testUtils.toDecimal(account.balance) === acctData.balance);
        assert(testUtils.toDecimal(account.nonce) === acctData.nonce);

        // validate the postcondition of other accounts
        delete testData.post[testData.exec.address];
        var keysOfPost = Object.keys(testData.post);
        async.each(keysOfPost, function(key, callback) {
          acctData = testData.post[key];

          state.get(new Buffer(key, 'hex'), function(err, raw) {
            assert(!err);

            account = new Account(raw);
            assert(testUtils.toDecimal(account.balance) === acctData.balance);
            assert(testUtils.toDecimal(account.nonce) === acctData.nonce);

            // validate storage
            var storageKeys = Object.keys(acctData.storage);
            if (storageKeys.length > 0) {
              state.root = account.stateRoot.toString('hex');
              storageKeys.forEach(function(skey) {
                state.get(testUtils.address(skey), function(err, data) {
                  assert(!err);
                  assert(rlp.decode(data).toString('hex') === acctData.storage[skey].slice(2));
                  callback();
                });
              });
            } else {
              callback();
            }
          });
        }, done);
      });
    });
  })

});
{'fraction_non_alphanumeric': 0.13895720609936055, 'fraction_numerical': 0.0014756517461878996, 'mean_word_length': 2.3718905472636815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '2000579', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2274, 'n_words': 412}