diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 000000000..8043cc1a4 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,63 @@ +name: Lint + +on: + push: + branches: + - main + - master + +jobs: + unit_tests: + strategy: + matrix: + go-version: [1.20.x] + os: [ubuntu-latest, macos-latest, windows-latest] + include: + - go-version: 1.17.x + os: ubuntu-latest + - go-version: 1.18.x + os: ubuntu-latest + - go-version: 1.19.x + os: ubuntu-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: v1.54 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # + # Note: By default, the `.golangci.yml` file should be at the root of the repository. + # The location of the configuration file can be changed by using `--config=` + # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true, then all caching functionality will be completely disabled, + # takes precedence over all other caching options. + skip-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/go/pkg. + skip-pkg-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. + skip-build-cache: true + + # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. + # install-mode: "goinstall" diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml new file mode 100644 index 000000000..cb341e55c --- /dev/null +++ b/.github/workflows/qodana_code_quality.yml @@ -0,0 +1,56 @@ +name: Test + +on: [push, pull_request] + +jobs: + unit_tests: + strategy: + matrix: + go-version: [1.21.x] + os: [ubuntu-latest, macos-latest, windows-latest] + include: + - go-version: 1.19.x + os: ubuntu-latest + - go-version: 1.20.x + os: ubuntu-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Make all + run: make all + + - name: Make Test + run: make test + test_coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: 1.21.x + + - name: Make all + run: make all + + - name: Setup + run: mkdir -p .qodana/code-coverage + + - name: Make Coverage + run: make test-coverage + + - name: 'Qodana Scan' + uses: JetBrains/qodana-action@v2023.3 + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} + with: + pr-mode: true diff --git a/.github/workflows/staticcheck.yaml b/.github/workflows/staticcheck.yaml new file mode 100644 index 000000000..879cf8f7c --- /dev/null +++ b/.github/workflows/staticcheck.yaml @@ -0,0 +1,14 @@ +name: "CI" +on: ["push", "pull_request"] + +jobs: + ci: + name: "Run CI" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + - uses: dominikh/staticcheck-action@v1.2.0 + with: + version: "2022.1.1" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f1a309824..cb4cc9d64 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,6 +2,10 @@ name: Test on: [push, pull_request] +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} + jobs: unit_tests: strategy: @@ -14,7 +18,7 @@ jobs: - go-version: 1.18.x os: ubuntu-latest - go-version: 1.19.x - os: ubuntu-latest + os: ubuntu-latest runs-on: ${{ matrix.os }} steps: - name: Checkout code @@ -27,6 +31,6 @@ jobs: - name: Make all run: make all - + - name: Make Test run: make test diff --git a/.gitignore b/.gitignore index 0d003a229..9515abbda 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,6 @@ package.json /.vscode/ /vendor/ -.fake_gopath_suffix \ No newline at end of file +.fake_gopath_suffix + +.idea diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 000000000..ce704cde0 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + { + "lastFilter": { + "state": "OPEN", + "assignee": "darrenvechain" + } +} + + + + + + + + + + + + + { + "associatedIndex": 7 +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + file://$PROJECT_DIR$/api/blocks/blocks.go + 121 + + + file://$PROJECT_DIR$/cmd/thor/flags.go + 62 + + + file://$PROJECT_DIR$/api/api.go + 62 + + + file://$PROJECT_DIR$/api/api.go + 61 + + + + + + + + + + + \ No newline at end of file diff --git a/Makefile b/Makefile index e6384556f..a52f78cf1 100644 --- a/Makefile +++ b/Makefile @@ -42,8 +42,11 @@ all: thor disco clean: -rm -rf \ $(CURDIR)/bin/thor \ -$(CURDIR)/bin/disco +$(CURDIR)/bin/disco test:| go_version_check @go test -cover $(PACKAGES) + +test-coverage:| go_version_check + @go test -race -coverprofile=.qodana/code-coverage/coverage.out -covermode=atomic $(PACKAGES) diff --git a/api/doc/thor.yaml b/api/doc/thor.yaml index d9e51ad16..6dd3eb2a6 100644 --- a/api/doc/thor.yaml +++ b/api/doc/thor.yaml @@ -29,7 +29,7 @@ tags: description: Subscribe interested subjects - name: Debug description: Debug utilities - + paths: /accounts/{address}: parameters: @@ -236,7 +236,7 @@ paths: schema: allOf: - $ref: '#/components/schemas/Receipt' - properties: + properties: meta: $ref: '#/components/schemas/ReceiptMeta' @@ -285,7 +285,7 @@ paths: - $ref: '#/components/schemas/IsFinalized' properties: transactions: - description: transaction IDs + description: transaction IDs type: array items: type: string @@ -400,7 +400,7 @@ paths: summary: (Websocket) Subscribe new blocks parameters: - $ref: '#/components/parameters/PositionInQuery' - + responses: '200': description: OK @@ -425,7 +425,7 @@ paths: summary: (Websocket) Subscribe new events description: | which satisfy criteria in query. - + parameters: - $ref: '#/components/parameters/PositionInQuery' - name: addr @@ -470,8 +470,8 @@ paths: properties: meta: $ref: '#/components/schemas/LogMeta' - - + + /subscriptions/transfer: get: tags: @@ -576,7 +576,7 @@ paths: schema: allOf: - $ref: '#/components/schemas/ClauseTracerOption' - - $ref: '#/components/schemas/TracerOption' + - $ref: '#/components/schemas/TracerOption' responses: '200': description: OK @@ -586,7 +586,7 @@ paths: type: object /debug/tracers/call: - post: + post: tags: - Debug summary: Create a tracer @@ -786,7 +786,7 @@ components: txsRoot: type: string format: bytes32 - description: root hash of transactions in the block + description: root hash of transactions in the block example: '0x89dfd9fcd10c9e53d68592cf8b540b280b72d381b868523223992f3e09a806bb' txsFeatures: type: integer @@ -986,7 +986,7 @@ components: gas: 50000 gasPrice: '1000000000000000' caller: '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed' - + ExtendedCallData: properties: provedWork: @@ -1055,11 +1055,11 @@ components: clauses: - to: '0x5034aa590125b64023a0262112b98d72e3c8e40e' value: '0xde0b6b3a7640000' - data: '0x5665436861696e2054686f72' + data: '0x5665436861696e2054686f72' gas: 50000 gasPrice: '1000000000000000' caller: '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed' - + BatchCallResult: type: array items: @@ -1103,12 +1103,12 @@ components: description: | defines the unit of `from` and `to`. `block` means block number, `time` means block timestamp, default to `block`. - + from: type: integer format: uint64 example: 0 - + to: type: integer format: uint64 @@ -1127,7 +1127,7 @@ components: ``` refers to the range from block 10 to block 1000. `null` stands for the full range. - + EventCriteria: properties: address: @@ -1156,7 +1156,7 @@ components: address: "0x0000000000000000000000000000456E65726779" topic0: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' topic1: '0x0000000000000000000000005034aa590125b64023a0262112b98d72e3c8e40e' - + EventFilter: properties: range: @@ -1174,7 +1174,7 @@ components: enum: - asc - desc - + TransferCriteria: properties: txOrigin: @@ -1204,7 +1204,7 @@ components: enum: - asc - desc - + PeerStats: properties: name: @@ -1235,15 +1235,15 @@ components: type: string example: id: '0x4de71f2d588aa8a1ea00fe8312d92966da424d9939a511fc0be81e65fad52af8' - - + + Obsolete: properties: obsolete: type: boolean description: | indicates whether the block containing this data become branch block - + ClauseTracerOption: properties: target: @@ -1346,7 +1346,7 @@ components: format: uint32 description: | the number of hash functions for bloom filter - example: 3 + example: 3 Beat2: allOf: @@ -1363,7 +1363,7 @@ components: isTrunk: type: boolean description: whether the block is on the trunk - + IsFinalized: properties: isFinalized: @@ -1452,7 +1452,7 @@ components: schema: type: string example: '0x9bcc6526a76ae560244f698805cc001977246cb92c2b4f1e2b7a204e445409ea' - + PositionInQuery: name: pos in: query diff --git a/go.sum b/go.sum index 4de2f0b98..aebcc2778 100644 --- a/go.sum +++ b/go.sum @@ -146,8 +146,11 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= @@ -191,13 +194,15 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -205,8 +210,9 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 000000000..8d8e0bbb6 --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,2 @@ +version: "1.0" +linter: jetbrains/qodana-go:2023.3