Skip to content

Commit

Permalink
Add CI configuration (#4)
Browse files Browse the repository at this point in the history
... and fix linter errors.
  • Loading branch information
kazarena authored Apr 11, 2022
1 parent 615dedb commit 756b06f
Show file tree
Hide file tree
Showing 27 changed files with 364 additions and 197 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: lib/go/iinft
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.16.*'

- name: Checkout code
uses: actions/checkout@v2

- id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

- name: golangci-lint
uses: golangci/[email protected]
with:
args: "--out-${NO_FUTURE}format colored-line-number --timeout 5m"
working-directory: lib/go/iinft
skip-pkg-cache: true
skip-build-cache: true

tidy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.16.*'
- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: zencargo/github-action-go-mod-tidy@v1
with:
path: lib/go/iinft
go-version: 1.16

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.16.*'
- name: Set up Cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: make test


2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ _references
lib/go/iinft/bin

# Flow emulator
flowdb
flowdb
64 changes: 64 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
linters-settings:
errcheck:
check-type-assertions: true
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
check-shadowing: true
nolintlint:
require-explanation: true
require-specific: true
funlen:
lines: 100
statements: 40

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- contextcheck
- depguard
- dogsled
# - dupl
- errcheck
- errorlint
- exportloopref
- exhaustive
- goconst
# - gocritic
- gofmt
- goimports
# - gomnd
- gocyclo
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- nolintlint
- nakedret
- prealloc
- predeclared
- revive
- staticcheck
- stylecheck
- thelper
- typecheck
- unconvert
- unparam
- unused
- wastedassign

run:
issues-exit-code: 1

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# sequel-flow-contracts
Flow smart contracts for Sequel
[![ci](https://github.com/piprate/sequel-flow-contracts/actions/workflows/ci.yml/badge.svg)](https://github.com/piprate/sequel-flow-contracts/actions/workflows/ci.yml)

# Flow contracts for Sequel

* Flow contracts for Sequel
* Supporting Go framework
2 changes: 1 addition & 1 deletion lib/go/iinft/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (f *fileLoader) WriteFile(filename string, data []byte, perm os.FileMode) e
}

// NewGoWithTheFlowFS creates a new local go with the flow client
func NewGoWithTheFlowFS(flowBasePath string, network string, inMemory, enableTxFees bool) (*gwtf.GoWithTheFlow, error) {
func NewGoWithTheFlowFS(flowBasePath, network string, inMemory, enableTxFees bool) (*gwtf.GoWithTheFlow, error) {
return NewGoWithTheFlowError(&fileLoader{
baseDir: flowBasePath,
fsLoader: &afero.Afero{Fs: afero.NewOsFs()},
Expand Down
6 changes: 4 additions & 2 deletions lib/go/iinft/evergreen/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ func ProfileFromCadence(val cadence.Value) (*Profile, error) {
Roles: []*Role{},
}

rolesArray := valStruct.Fields[1].(cadence.Array)
rolesArray, ok := valStruct.Fields[1].(cadence.Array)
if !ok {
return nil, errors.New("bad Evergreen Profile value")
}
for _, roleVal := range rolesArray.Values {
role, err := RoleFromCadence(roleVal)
if err != nil {
return nil, err
}
res.Roles = append(res.Roles, role)

}

return &res, nil
Expand Down
1 change: 0 additions & 1 deletion lib/go/iinft/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.16

require (
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/kevinburke/go-bindata v3.22.0+incompatible
github.com/onflow/cadence v0.23.2
github.com/onflow/flow-cli v0.33.0
github.com/onflow/flow-emulator v0.31.0
Expand Down
1 change: 0 additions & 1 deletion lib/go/iinft/gwtf/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func (f *GoWithTheFlow) CreateAccounts(saAccountName string) *GoWithTheFlow {
}

return gwtf

}

// CreateAccountsE ensures that all accounts present in the deployment block for the given network is present
Expand Down
1 change: 0 additions & 1 deletion lib/go/iinft/gwtf/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ func TestErrorsInAccountCreation(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "could not find account with address 179b6b1cb6755e3")
})

}
25 changes: 13 additions & 12 deletions lib/go/iinft/gwtf/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func (tb FlowTransactionBuilder) Test(t *testing.T) TransactionResult {
locale, _ := time.LoadLocation("UTC")
time.Local = locale
events, err := tb.RunE()
var formattedEvents []*FormatedEvent
for _, event := range events {
formattedEvents := make([]*FormatedEvent, len(events))
for i, event := range events {
ev := ParseEvent(event, uint64(0), time.Unix(0, 0), []string{})
formattedEvents = append(formattedEvents, ev)
formattedEvents[i] = ev
}
return TransactionResult{
Err: err,
Expand All @@ -37,6 +37,7 @@ func (t TransactionResult) AssertFailure(msg string) TransactionResult {
}
return t
}

func (t TransactionResult) AssertSuccess() TransactionResult {
assert.NoError(t.Testing, t.Err)
return t
Expand All @@ -45,8 +46,8 @@ func (t TransactionResult) AssertSuccess() TransactionResult {
func (t TransactionResult) AssertEventCount(number int) TransactionResult {
assert.Equal(t.Testing, number, len(t.Events))
return t

}

func (t TransactionResult) AssertNoEvents() TransactionResult {
assert.Empty(t.Testing, t.Events)

Expand All @@ -58,9 +59,9 @@ func (t TransactionResult) AssertNoEvents() TransactionResult {
}

func (t TransactionResult) AssertEmitEventName(event ...string) TransactionResult {
var eventNames []string
for _, fe := range t.Events {
eventNames = append(eventNames, fe.Name)
eventNames := make([]string, len(t.Events))
for i, fe := range t.Events {
eventNames[i] = fe.Name
}

for _, ev := range event {
Expand All @@ -74,11 +75,11 @@ func (t TransactionResult) AssertEmitEventName(event ...string) TransactionResul
return t
}

func (t TransactionResult) AssertEmitEventJson(event ...string) TransactionResult {
func (t TransactionResult) AssertEmitEventJSON(event ...string) TransactionResult {

var jsonEvents []string
for _, fe := range t.Events {
jsonEvents = append(jsonEvents, fe.String())
jsonEvents := make([]string, len(t.Events))
for i, fe := range t.Events {
jsonEvents[i] = fe.String()
}

for _, ev := range event {
Expand All @@ -96,7 +97,7 @@ func (t TransactionResult) AssertPartialEvent(expected *FormatedEvent) Transacti

events := t.Events
for index, ev := range events {
//todo do we need more then just name here?
// TODO do we need more then just name here?
if ev.Name == expected.Name {
for key := range ev.Fields {
_, exist := expected.Fields[key]
Expand Down
4 changes: 2 additions & 2 deletions lib/go/iinft/gwtf/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/onflow/cadence"
)

// CadenceValueToJsonString converts a cadence.Value into a json pretty printed string
func CadenceValueToJsonString(value cadence.Value) string {
// CadenceValueToJSONString converts a cadence.Value into a json pretty printed string
func CadenceValueToJSONString(value cadence.Value) string {
if value == nil {
return "{}"
}
Expand Down
19 changes: 9 additions & 10 deletions lib/go/iinft/gwtf/cadence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import (
"github.com/stretchr/testify/assert"
)

func TestCadenceValueToJsonString(t *testing.T) {
func TestCadenceValueToJSONString(t *testing.T) {

t.Parallel()
t.Run("Empty value should be empty json object", func(t *testing.T) {
value := CadenceValueToJsonString(nil)
value := CadenceValueToJSONString(nil)
assert.Equal(t, "{}", value)
})

t.Run("Empty optional should be empty string", func(t *testing.T) {
value := CadenceValueToJsonString(cadence.NewOptional(nil))
value := CadenceValueToJSONString(cadence.NewOptional(nil))
assert.Equal(t, `""`, value)
})
t.Run("Unwrap optional", func(t *testing.T) {
value := CadenceValueToJsonString(cadence.NewOptional(NewCadenceString("foo")))
value := CadenceValueToJSONString(cadence.NewOptional(NewCadenceString("foo")))
assert.Equal(t, `"foo"`, value)
})
t.Run("Array", func(t *testing.T) {
value := CadenceValueToJsonString(cadence.NewArray([]cadence.Value{NewCadenceString("foo"), NewCadenceString("bar")}))
value := CadenceValueToJSONString(cadence.NewArray([]cadence.Value{NewCadenceString("foo"), NewCadenceString("bar")}))
assert.Equal(t, `[
"foo",
"bar"
Expand All @@ -33,7 +33,7 @@ func TestCadenceValueToJsonString(t *testing.T) {

t.Run("Dictionary", func(t *testing.T) {
dict := cadence.NewDictionary([]cadence.KeyValuePair{{Key: NewCadenceString("foo"), Value: NewCadenceString("bar")}})
value := CadenceValueToJsonString(dict)
value := CadenceValueToJSONString(dict)
assert.Equal(t, `{
"foo": "bar"
}`, value)
Expand All @@ -42,7 +42,7 @@ func TestCadenceValueToJsonString(t *testing.T) {
t.Run("Dictionary nested", func(t *testing.T) {
subDict := cadence.NewDictionary([]cadence.KeyValuePair{{Key: NewCadenceString("foo"), Value: NewCadenceString("bar")}})
dict := cadence.NewDictionary([]cadence.KeyValuePair{{Key: NewCadenceString("foo"), Value: NewCadenceString("bar")}, {Key: NewCadenceString("subdict"), Value: subDict}})
value := CadenceValueToJsonString(dict)
value := CadenceValueToJSONString(dict)
assert.Equal(t, `{
"foo": "bar",
"subdict": {
Expand All @@ -53,7 +53,7 @@ func TestCadenceValueToJsonString(t *testing.T) {

t.Run("Dictionary", func(t *testing.T) {
dict := cadence.NewDictionary([]cadence.KeyValuePair{{Key: cadence.NewUInt64(1), Value: cadence.NewUInt64(1)}})
value := CadenceValueToJsonString(dict)
value := CadenceValueToJSONString(dict)
assert.Equal(t, `{
"1": "1"
}`, value)
Expand All @@ -69,12 +69,11 @@ func TestCadenceValueToJsonString(t *testing.T) {
}},
},
}
value := CadenceValueToJsonString(s)
value := CadenceValueToJSONString(s)
assert.Equal(t, `{
"foo": "bar"
}`, value)
})

}

func NewCadenceString(value string) cadence.String {
Expand Down
Loading

0 comments on commit 756b06f

Please sign in to comment.