aergoio/aergo

View on GitHub
contract/vm_dummy/vm_dummy.go

Summary

Maintainability
C
1 day
Test Coverage
B
81%

File vm_dummy.go has 599 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package vm_dummy

// helper functions
import (
    "context"
Severity: Minor
Found in contract/vm_dummy/vm_dummy.go - About 4 hrs to fix

    Function contractFrame has 71 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func contractFrame(l luaTxContract, bs *state.BlockState, cdb contract.ChainAccessor, receiptTx db.Transaction,
        run func(s, c *state.AccountState, id types.AccountID, cs *statedb.ContractState) (string, []*types.Event, *big.Int, error)) error {
    
        creatorId := types.ToAccountID(l.sender())
        creatorState, err := state.GetAccountState(l.sender(), bs.StateDB)
    Severity: Minor
    Found in contract/vm_dummy/vm_dummy.go - About 1 hr to fix

      Function contractFrame has 11 return statements (exceeds 4 allowed).
      Open

      func contractFrame(l luaTxContract, bs *state.BlockState, cdb contract.ChainAccessor, receiptTx db.Transaction,
          run func(s, c *state.AccountState, id types.AccountID, cs *statedb.ContractState) (string, []*types.Event, *big.Int, error)) error {
      
          creatorId := types.ToAccountID(l.sender())
          creatorState, err := state.GetAccountState(l.sender(), bs.StateDB)
      Severity: Major
      Found in contract/vm_dummy/vm_dummy.go - About 1 hr to fix

        Method DummyChain.Query has 7 return statements (exceeds 4 allowed).
        Open

        func (bc *DummyChain) Query(contract_name, queryInfo, expectedErr string, expectedRvs ...string) error {
            cState, err := statedb.OpenContractStateAccount(contract.StrHash(contract_name), bc.sdb.GetStateDB())
            if err != nil {
                return err
            }
        Severity: Major
        Found in contract/vm_dummy/vm_dummy.go - About 45 mins to fix

          Method luaTxCall.run has 7 return statements (exceeds 4 allowed).
          Open

          func (l *luaTxCall) run(execCtx context.Context, bs *state.BlockState, bc *DummyChain, bi *types.BlockHeaderInfo, receiptTx db.Transaction) error {
              err := contractFrame(l, bs, bc, receiptTx,
                  func(sender, contractV *state.AccountState, contractId types.AccountID, eContractState *statedb.ContractState) (string, []*types.Event, *big.Int, error) {
                      ctx := contract.NewVmContext(execCtx, bs, bc, sender, contractV, eContractState, sender.ID(), l.Hash(), bi, "", true, false, contractV.State().SqlRecoveryPoint, contract.BlockFactory, l.amount(), math.MaxUint64, l.feeDelegate)
          
          
          Severity: Major
          Found in contract/vm_dummy/vm_dummy.go - About 45 mins to fix

            Method DummyChain.QueryOnly has 6 return statements (exceeds 4 allowed).
            Open

            func (bc *DummyChain) QueryOnly(contract_name, queryInfo string, expectedErr string) (bool, string, error) {
                cState, err := statedb.OpenContractStateAccount(contract.StrHash(contract_name), bc.sdb.GetStateDB())
                if err != nil {
                    return false, "", err
                }
            Severity: Major
            Found in contract/vm_dummy/vm_dummy.go - About 40 mins to fix

              Method luaTxSend.run has 5 return statements (exceeds 4 allowed).
              Open

              func (l *luaTxSend) run(execCtx context.Context, bs *state.BlockState, bc *DummyChain, bi *types.BlockHeaderInfo, receiptTx db.Transaction) error {
                  senderID := types.ToAccountID(l.sender)
                  receiverID := types.ToAccountID(l.receiver)
              
                  if senderID == receiverID {
              Severity: Major
              Found in contract/vm_dummy/vm_dummy.go - About 35 mins to fix

                Function contractFrame has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                Open

                func contractFrame(l luaTxContract, bs *state.BlockState, cdb contract.ChainAccessor, receiptTx db.Transaction,
                    run func(s, c *state.AccountState, id types.AccountID, cs *statedb.ContractState) (string, []*types.Event, *big.Int, error)) error {
                
                    creatorId := types.ToAccountID(l.sender())
                    creatorState, err := state.GetAccountState(l.sender(), bs.StateDB)
                Severity: Minor
                Found in contract/vm_dummy/vm_dummy.go - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                There are no issues that match your filters.

                Category
                Status