kleros/kleros-v2

View on GitHub
contracts/test/arbitration/draw.ts

Summary

Maintainability
F
1 wk
Test Coverage

File draw.ts has 369 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
import { deployments, ethers, getNamedAccounts, network } from "hardhat";
import { toBigInt, ContractTransactionResponse, HDNodeWallet } from "ethers";
import {
  PNK,
Severity: Minor
Found in contracts/test/arbitration/draw.ts - About 4 hrs to fix

Function draw has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Wontfix

  const draw = async (
    stake: SetStake,
    createDisputeCourtId: number,
    expectFromDraw: ExpectFromDraw,
    unstake: SetStake
Severity: Major
Found in contracts/test/arbitration/draw.ts - About 2 hrs to fix

Function expectFromDraw has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    const expectFromDraw = async (drawTx: Promise<ContractTransactionResponse>) => {
      console.log((await core.getRoundInfo(0, 0)).drawIterations);
      expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);

      const tx = await (await drawTx).wait();
Severity: Minor
Found in contracts/test/arbitration/draw.ts - About 1 hr to fix

Function expectFromDraw has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    const expectFromDraw = async (drawTx: Promise<ContractTransactionResponse>) => {
      console.log((await core.getRoundInfo(0, 0)).drawIterations);
      expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);

      const tx = await (await drawTx).wait();
Severity: Minor
Found in contracts/test/arbitration/draw.ts - About 1 hr to fix

Function expectFromDraw has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    const expectFromDraw = async (drawTx: Promise<ContractTransactionResponse>) => {
      console.log((await core.getRoundInfo(0, 0)).drawIterations);
      expect(await core.getRoundInfo(0, 0).then((round) => round.drawIterations)).to.equal(3);

      const tx = await (await drawTx).wait();
Severity: Minor
Found in contracts/test/arbitration/draw.ts - About 1 hr to fix

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  it("Stakes in subcourt and should draw jurors in subcourt", async () => {
    const stake = async (wallet: HDNodeWallet) => {
      await core.connect(wallet).setStake(CHILD_COURT, ONE_THOUSAND_PNK * 5n, { gasLimit: 5000000 });
    };
    let countedDraws: CountedDraws;
Severity: Major
Found in contracts/test/arbitration/draw.ts and 1 other location - About 3 days to fix
contracts/test/arbitration/draw.ts on lines 301..361

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 637.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  it("Stakes in subcourt and should draw jurors in parent court", async () => {
    const stake = async (wallet: HDNodeWallet) => {
      await core.connect(wallet).setStake(CHILD_COURT, ONE_THOUSAND_PNK * 5n, { gasLimit: 5000000 });
    };
    let countedDraws: CountedDraws;
Severity: Major
Found in contracts/test/arbitration/draw.ts and 1 other location - About 3 days to fix
contracts/test/arbitration/draw.ts on lines 363..423

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 637.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Wontfix

      expect(
        await sortitionModule.getJurorBalance(wallet.address, PARENT_COURT),
        "No locked stake in the parent court"
      ).to.deep.equal([
        0, // totalStaked
Severity: Minor
Found in contracts/test/arbitration/draw.ts and 1 other location - About 50 mins to fix
contracts/test/arbitration/draw.ts on lines 287..295

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 52.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Wontfix

      expect(
        await sortitionModule.getJurorBalance(wallet.address, CHILD_COURT),
        "No locked stake in the child court"
      ).to.deep.equal([
        0, // totalStaked
Severity: Minor
Found in contracts/test/arbitration/draw.ts and 1 other location - About 50 mins to fix
contracts/test/arbitration/draw.ts on lines 278..286

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 52.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Shadowed name: 'draw'
Open

    return draws.reduce((acc: { [address: string]: number }, draw) => {
Severity: Minor
Found in contracts/test/arbitration/draw.ts by tslint

Rule: no-shadowed-variable

Disallows shadowing variable declarations.

Rationale

When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs. Shadowing makes it impossible to access the variable in the containing scope and obscures to what value an identifier actually refers. Compare the following snippets:

const a = 'no shadow';
function print() {
    console.log(a);
}
print(); // logs 'no shadow'.
const a = 'no shadow';
function print() {
    const a = 'shadow'; // TSLint will complain here.
    console.log(a);
}
print(); // logs 'shadow'.

ESLint has an equivalent rule. For more background information, refer to this MDN closure doc.

Config

You can optionally pass an object to disable checking for certain kinds of declarations. Possible keys are "class", "enum", "function", "import", "interface", "namespace", "typeAlias" and "typeParameter". You can also pass "underscore" to ignore variable names that begin with _. Just set the value to false for the check you want to disable. All checks default to true, i.e. are enabled by default. Note that you cannot disable variables and parameters.

The option "temporalDeadZone" defaults to true which shows errors when shadowing block scoped declarations in their temporal dead zone. When set to false parameters, classes, enums and variables declared with let or const are not considered shadowed if the shadowing occurs within their temporal dead zone.

The following example shows how the "temporalDeadZone" option changes the linting result:

function fn(value) {
    if (value) {
        const tmp = value; // no error on this line if "temporalDeadZone" is false
        return tmp;
    }
    let tmp = undefined;
    if (!value) {
        const tmp = value; // this line always contains an error
        return tmp;
    }
}
Examples
"no-shadowed-variable": true
"no-shadowed-variable": true,[object Object]
Schema
{
  "type": "object",
  "properties": {
    "class": {
      "type": "boolean"
    },
    "enum": {
      "type": "boolean"
    },
    "function": {
      "type": "boolean"
    },
    "import": {
      "type": "boolean"
    },
    "interface": {
      "type": "boolean"
    },
    "namespace": {
      "type": "boolean"
    },
    "typeAlias": {
      "type": "boolean"
    },
    "typeParameter": {
      "type": "boolean"
    },
    "temporalDeadZone": {
      "type": "boolean"
    },
    "underscore": {
      "type": "boolean"
    }
  }
}

For more information see this page.

Array type using 'Array<t>' is forbidden. Use 'T[]' instead.</t>
Open

    const draws: Array<any> = await core.queryFilter(core.filters.Draw(), blockNumber, blockNumber);
Severity: Minor
Found in contracts/test/arbitration/draw.ts by tslint

Rule: array-type

Requires using either 'T[]' or 'Array<t>' for arrays.</t>

Notes
  • TypeScript Only
  • Has Fix

Config

One of the following arguments must be provided:

  • "array" enforces use of T[] for all types T.
  • "generic" enforces use of Array<T> for all types T.
  • "array-simple" enforces use of T[] if T is a simple type (primitive or type reference).
Examples
"array-type": true,array
"array-type": true,generic
"array-type": true,array-simple
Schema
{
  "type": "string",
  "enum": [
    "array",
    "generic",
    "array-simple"
  ]
}

For more information see this page.

There are no issues that match your filters.

Category
Status