{"size": 1882, "ext": "js", "max_stars_repo_path": "test/bulk-transfer.js", "max_stars_repo_name": "CyberAudit/CYBERAudit", "max_stars_repo_stars_event_min_datetime": "2018-11-16T16:36:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-18T17:07:50.000Z", "max_issues_repo_path": "test/bulk-transfer.js", "max_issues_repo_name": "CyberAudit/CYBERAudit", "max_issues_repo_issues_event_min_datetime": "2020-09-04T14:44:09.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T22:06:27.000Z", "max_forks_repo_path": "test/bulk-transfer.js", "max_forks_repo_name": "CyberAudit/CYBERAudit", "max_forks_repo_forks_event_min_datetime": "2021-12-13T10:52:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-13T10:52:41.000Z"}
{"max_stars_count": 2, "max_issues_count": 3, "max_forks_count": 1, "avg_line_length": 27.6764705882, "max_line_length": 95, "alphanum_fraction": 0.5908607864}
const Token = artifacts.require("./TokenBase.sol");
const BigNumber = require("bignumber.js");
const EVMRevert = require("./helpers/EVMRevert").EVMRevert;

require("chai")
  .use(require("chai-as-promised"))
  .use(require("chai-bignumber")(BigNumber))
  .should();

contract("BulkTransfer", function (accounts) {
  describe("Bulk Token Transfer Ruleset", async () => {
    let token;

    beforeEach(async () => {
      token = await Token.new();
      await token.addAdmin(accounts[2]);
    });

    it("must correctly perform bulk transfers.", async () => {
      const destinations = [];
      const balances = [];

      for (let i = 3; i < 7; i++) {
        destinations.push(accounts[i]);
        balances.push(i);
      };

      await token.bulkTransfer(destinations, balances);

      for (let i = 0; i < destinations.length; i++) {
        let balance = await token.balanceOf(destinations[i]);
        assert.equal(balance, balances[i]);
      };
    });

    it("must not allow non-whitelisted (non-admin) addresses to bulk transfers.", async () => {
      const balances = [];
      const destinations = [];

      for (let i = 1; i < 4; i++) {
        destinations.push(accounts[i]);
        balances.push(i);
      };

      await token.bulkTransfer(destinations, balances, {
        from: accounts[1]
      }).should.be.rejectedWith(EVMRevert);
    });

    it("must revert when the balance is less than the sum.", async () => {
      const balances = [];
      const destinations = [];

      for (let i = 1; i < 4; i++) {
        destinations.push(accounts[i]);
        balances.push(i);
      };

      let currentBalance = await token.balanceOf(accounts[0]);

      await token.transfer(accounts[6], currentBalance);
      await token.bulkTransfer(destinations, balances, {
        from: accounts[0]
      }).should.be.rejectedWith(EVMRevert);
    });
  });
});
