{"size": 1377, "ext": "js", "max_stars_repo_path": "packages/augur-node/test/unit/blockchain/log-processors/crowdsourcer-redeemed.js", "max_stars_repo_name": "zackster/augur", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/augur-node/test/unit/blockchain/log-processors/crowdsourcer-redeemed.js", "max_issues_repo_name": "zackster/augur", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/augur-node/test/unit/blockchain/log-processors/crowdsourcer-redeemed.js", "max_forks_repo_name": "zackster/augur", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.6, "max_line_length": 150, "alphanum_fraction": 0.6717501816}
const setupTestDb = require("test.database");
const { processDisputeCrowdsourcerRedeemedLog, processDisputeCrowdsourcerRedeemedLogRemoval } = require("src/blockchain/log-processors/crowdsourcer");

function getRedeemed(db) {
  return db.select(["reporter", "crowdsourcer", "amountRedeemed", "repReceived", "reportingFeesReceived"]).from("crowdsourcer_redeemed");
}

describe("blockchain/log-processors/crowdsourcer-redeemed", () => {
  let db;
  beforeEach(async () => {
    db = await setupTestDb();
  });

  const log = {
    transactionHash: "TRANSACTION_HASH",
    logIndex: 0,
    blockNumber: 1400101,
    reporter: "REPORTER",
    disputeCrowdsourcer: "DISPUTE_CROWDSOURCER",
    amountRedeemed: "200",
    repReceived: "400",
    reportingFeesReceived: "900",
  };
  test("Redeemed", async () => {
    return db.transaction(async (trx) => {
      await(await processDisputeCrowdsourcerRedeemedLog({}, log))(trx);

      await expect(getRedeemed(trx)).resolves.toEqual([{
        amountRedeemed: "200",
        crowdsourcer: "DISPUTE_CROWDSOURCER",
        repReceived: "400",
        reporter: "REPORTER",
        reportingFeesReceived: "900",
      }]);
      await(await processDisputeCrowdsourcerRedeemedLogRemoval({}, log))(trx);

      await expect(getRedeemed(trx)).resolves.toEqual([]);
    });
  });

  afterEach(async () => {
    await db.destroy();
  });
});
