Skip to content

Commit

Permalink
CICD: Fixing golangci-lint and github action (#4483)
Browse files Browse the repository at this point in the history
  • Loading branch information
algojack authored Aug 30, 2022
1 parent 8257910 commit e83acec
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 70 deletions.
2 changes: 0 additions & 2 deletions .golangci-warnings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ issues:
exclude:
# ignore govet false positive fixed in https://github.com/golang/go/issues/45043
- "sigchanyzer: misuse of unbuffered os.Signal channel as argument to signal.Notify"
# ignore golint false positive fixed in https://github.com/golang/lint/pull/487
- "exported method (.*).Unwrap` should have comment or be unexported"
# ignore issues about the way we use _struct fields to define encoding settings
- "`_struct` is unused"

Expand Down
16 changes: 14 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
timeout: 5m
tests: false
tests: true

linters:
# default: deadcode, errcheck, gosimple, govet, ineffassign, staticcheck, typecheck, unused, varcheck
Expand Down Expand Up @@ -66,12 +66,24 @@ issues:
- "var-naming: don't use leading k in Go names"

exclude-rules:
- path: _test\.go
linters:
- errcheck
- gofmt
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
# - revive
- staticcheck
- typecheck
# Add all linters here -- Comment this block out for testing linters
- path: test/linttest/lintissues\.go
linters:
- errcheck
- gofmt
- golint
- revive
- govet
- ineffassign
- misspell
48 changes: 24 additions & 24 deletions ledger/internal/apptxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2479,7 +2479,7 @@ func TestInnerClearState(t *testing.T) {
eval := nextBlock(t, l)
txn(t, l, eval, &inner)
vb := endBlock(t, l, eval)
innerId := vb.Block().Payset[0].ApplicationID
innerID := vb.Block().Payset[0].ApplicationID

// Outer is a simple app that will invoke the given app (in ForeignApps[0])
// with the given OnCompletion (in ApplicationArgs[0]). Goal is to use it
Expand All @@ -2498,33 +2498,33 @@ itxn_begin
itxn_field OnCompletion
itxn_submit
`),
ForeignApps: []basics.AppIndex{innerId},
ForeignApps: []basics.AppIndex{innerID},
}

eval = nextBlock(t, l)
txn(t, l, eval, &outer)
vb = endBlock(t, l, eval)
outerId := vb.Block().Payset[0].ApplicationID
outerID := vb.Block().Payset[0].ApplicationID

fund := txntest.Txn{
Type: "pay",
Sender: addrs[0],
Receiver: outerId.Address(),
Receiver: outerID.Address(),
Amount: 1_000_000,
}

call := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApplicationID: outerId,
ApplicationID: outerID,
ApplicationArgs: [][]byte{{byte(transactions.OptInOC)}},
ForeignApps: []basics.AppIndex{innerId},
ForeignApps: []basics.AppIndex{innerID},
}
eval = nextBlock(t, l)
txns(t, l, eval, &fund, &call)
endBlock(t, l, eval)

outerAcct := lookup(t, l, outerId.Address())
outerAcct := lookup(t, l, outerID.Address())
require.Len(t, outerAcct.AppLocalStates, 1)
require.Equal(t, outerAcct.TotalAppSchema, basics.StateSchema{
NumUint: 2,
Expand All @@ -2536,7 +2536,7 @@ itxn_submit
txn(t, l, eval, &call)
endBlock(t, l, eval)

outerAcct = lookup(t, l, outerId.Address())
outerAcct = lookup(t, l, outerID.Address())
require.Empty(t, outerAcct.AppLocalStates)
require.Empty(t, outerAcct.TotalAppSchema)

Expand Down Expand Up @@ -2567,7 +2567,7 @@ b top
eval := nextBlock(t, l)
txn(t, l, eval, &badCallee)
vb := endBlock(t, l, eval)
badId := vb.Block().Payset[0].ApplicationID
badID := vb.Block().Payset[0].ApplicationID

// Outer is a simple app that will invoke the given app (in ForeignApps[0])
// with the given OnCompletion (in ApplicationArgs[0]). Goal is to use it
Expand Down Expand Up @@ -2603,33 +2603,33 @@ bnz skip // Don't do budget checking during optin
assert
skip:
`),
ForeignApps: []basics.AppIndex{badId},
ForeignApps: []basics.AppIndex{badID},
}

eval = nextBlock(t, l)
txn(t, l, eval, &outer)
vb = endBlock(t, l, eval)
outerId := vb.Block().Payset[0].ApplicationID
outerID := vb.Block().Payset[0].ApplicationID

fund := txntest.Txn{
Type: "pay",
Sender: addrs[0],
Receiver: outerId.Address(),
Receiver: outerID.Address(),
Amount: 1_000_000,
}

call := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApplicationID: outerId,
ApplicationID: outerID,
ApplicationArgs: [][]byte{{byte(transactions.OptInOC)}},
ForeignApps: []basics.AppIndex{badId},
ForeignApps: []basics.AppIndex{badID},
}
eval = nextBlock(t, l)
txns(t, l, eval, &fund, &call)
endBlock(t, l, eval)

outerAcct := lookup(t, l, outerId.Address())
outerAcct := lookup(t, l, outerID.Address())
require.Len(t, outerAcct.AppLocalStates, 1)

// When doing a clear state, `call` checks that budget wasn't stolen
Expand All @@ -2639,7 +2639,7 @@ skip:
endBlock(t, l, eval)

// Clearstate took effect, despite failure from infinite loop
outerAcct = lookup(t, l, outerId.Address())
outerAcct = lookup(t, l, outerID.Address())
require.Empty(t, outerAcct.AppLocalStates)
}

Expand Down Expand Up @@ -2697,8 +2697,8 @@ log
eval := nextBlock(t, l)
txns(t, l, eval, &inner, &waster)
vb := endBlock(t, l, eval)
innerId := vb.Block().Payset[0].ApplicationID
wasterId := vb.Block().Payset[1].ApplicationID
innerID := vb.Block().Payset[0].ApplicationID
wasterID := vb.Block().Payset[1].ApplicationID

// Grouper is a simple app that will invoke the given apps (in
// ForeignApps[0,1]) as a group, with the given OnCompletion (in
Expand Down Expand Up @@ -2730,27 +2730,27 @@ itxn_submit
eval = nextBlock(t, l)
txn(t, l, eval, &grouper)
vb = endBlock(t, l, eval)
grouperId := vb.Block().Payset[0].ApplicationID
grouperID := vb.Block().Payset[0].ApplicationID

fund := txntest.Txn{
Type: "pay",
Sender: addrs[0],
Receiver: grouperId.Address(),
Receiver: grouperID.Address(),
Amount: 1_000_000,
}

call := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApplicationID: grouperId,
ApplicationID: grouperID,
ApplicationArgs: [][]byte{{byte(transactions.OptInOC)}, {byte(transactions.OptInOC)}},
ForeignApps: []basics.AppIndex{wasterId, innerId},
ForeignApps: []basics.AppIndex{wasterID, innerID},
}
eval = nextBlock(t, l)
txns(t, l, eval, &fund, &call)
endBlock(t, l, eval)

gAcct := lookup(t, l, grouperId.Address())
gAcct := lookup(t, l, grouperID.Address())
require.Len(t, gAcct.AppLocalStates, 2)

call.ApplicationArgs = [][]byte{{byte(transactions.CloseOutOC)}, {byte(transactions.ClearStateOC)}}
Expand All @@ -2760,7 +2760,7 @@ itxn_submit
require.Len(t, vb.Block().Payset, 0)

// Clearstate did not take effect, since the caller tried to shortchange the CSP
gAcct = lookup(t, l, grouperId.Address())
gAcct = lookup(t, l, grouperID.Address())
require.Len(t, gAcct.AppLocalStates, 2)
}

Expand Down
16 changes: 8 additions & 8 deletions ledger/internal/eval_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,13 +1047,13 @@ func TestLogsInBlock(t *testing.T) {
}
vb := dl.fullBlock(&createTxn)
createInBlock := vb.Block().Payset[0]
appId := createInBlock.ApplyData.ApplicationID
appID := createInBlock.ApplyData.ApplicationID
require.Equal(t, "APP", createInBlock.ApplyData.EvalDelta.Logs[0])

optInTxn := txntest.Txn{
Type: protocol.ApplicationCallTx,
Sender: addrs[1],
ApplicationID: appId,
ApplicationID: appID,
OnCompletion: transactions.OptInOC,
}
vb = dl.fullBlock(&optInTxn)
Expand All @@ -1063,7 +1063,7 @@ func TestLogsInBlock(t *testing.T) {
clearTxn := txntest.Txn{
Type: protocol.ApplicationCallTx,
Sender: addrs[1],
ApplicationID: appId,
ApplicationID: appID,
OnCompletion: transactions.ClearStateOC,
}
vb = dl.fullBlock(&clearTxn)
Expand Down Expand Up @@ -1102,7 +1102,7 @@ func TestUnfundedSenders(t *testing.T) {

ghost := basics.Address{0x01}

asa_create := txntest.Txn{
asaCreate := txntest.Txn{
Type: "acfg",
Sender: addrs[0],
AssetParams: basics.AssetParams{
Expand All @@ -1113,12 +1113,12 @@ func TestUnfundedSenders(t *testing.T) {
},
}

app_create := txntest.Txn{
appCreate := txntest.Txn{
Type: "appl",
Sender: addrs[0],
}

dl.fullBlock(&asa_create, &app_create)
dl.fullBlock(&asaCreate, &appCreate)

// Advance so that rewardsLevel increases
for i := 1; i < 10; i++ {
Expand Down Expand Up @@ -1230,7 +1230,7 @@ func TestAppCallAppDuringInit(t *testing.T) {
dl.fullBlock()
}

call_in_init := txntest.Txn{
callInInit := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApprovalProgram: `
Expand All @@ -1251,6 +1251,6 @@ func TestAppCallAppDuringInit(t *testing.T) {
// In the old days, balances.Move would try to increase the rewardsState on the unfunded account
problem = "balance 0 below min"
}
dl.txn(&call_in_init, problem)
dl.txn(&callInInit, problem)
})
}
34 changes: 0 additions & 34 deletions scripts/travis/codegen_verification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,6 @@ eval "$(~/gimme "${GOLANG_VERSION}")"

make gen SHORT_PART_PERIOD=1

function runGoFmt() {
unformatted=$(gofmt -l .)
[ -z "$unformatted" ] && return 0

# Some files are not gofmt'd. Print message and fail.

echo >&2 "Go files must be formatted with gofmt. Please run:"
for fn in $unformatted; do
echo >&2 " gofmt -w $PWD/$fn"
done

return 1
}

function runGoLint() {
warningCount=$("$GOPATH"/bin/golangci-lint -c .golangci.yml | wc -l | tr -d ' ')
if [ "${warningCount}" = "0" ]; then
return 0
fi

echo >&2 "golangci-lint must be clean. Please run the following to list issues(${warningCount}):"
echo >&2 " make lint"

# run the linter again to output the actual issues
"$GOPATH"/bin/golangci-lint -c .golangci.yml >&2
return 1
}

echo "Running gofmt..."
runGoFmt

echo "Running golangci-lint..."
runGoLint

echo "Running check_license..."
./scripts/check_license.sh

Expand Down

0 comments on commit e83acec

Please sign in to comment.