Skip to content

Commit

Permalink
Merge branch 'cosmos/v0.44.x' of https://github.com/forbole/bdjuno in…
Browse files Browse the repository at this point in the history
…to chains/emoney/mainnet
  • Loading branch information
MonikaCat committed Feb 5, 2024
2 parents 951d13a + 3a3a3d9 commit b1e0e26
Show file tree
Hide file tree
Showing 44 changed files with 1,167 additions and 160 deletions.
41 changes: 20 additions & 21 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@ name: docker-build
on:
push:
branches:
- cosmos/*/*
- chains/*/*

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Set bdjuno chain_name
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Set BDJuno chain name 🔧
shell: bash
run: echo "CHAIN_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV
-
name: Set bdjuno version

- name: Set BDJuno version 🔧
shell: bash
run: echo "GITHUB_VERSION=$(git describe --tags)" >> $GITHUB_ENV
-
name: Prepare tags

- name: Prepare tags 🏷️
id: prep
run: |
DOCKER_IMAGE=${{ secrets.DOCKERHUB_BDJUNO_REPO }}
Expand All @@ -33,26 +31,27 @@ jobs:
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Determine Dockerfile to use
- name: Determine Dockerfile to use 🔍
run: |
if [[ -f Dockerfile.cosmwasm ]]; then
export DOCKERFILE=Dockerfile.cosmwasm
else
export DOCKERFILE=Dockerfile.default
fi
echo "DOCKERFILE=${DOCKERFILE}" >> $GITHUB_ENV
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub
uses: docker/login-action@v2
- name: Set up Docker Buildx 🧰
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub 👤
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v4

- name: Build and push 📤
uses: docker/build-push-action@v5
with:
context: .
file: "./${{ env.DOCKERFILE }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.2.0
- uses: amannn/action-semantic-pull-request@v5.4.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 14 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@ name: Lint
on:
pull_request:
push:
branches:
- master

jobs:
GolangCI:
name: golangci-lint
runs-on: ubuntu-latest
timeout-minutes: 6
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: technote-space/[email protected]
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Setup Go 🧰
uses: actions/setup-go@v5
with:
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/[email protected]
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- uses: golangci/[email protected]
with:
version: v1.51.1
args: --timeout 10m
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run lint ✅
if: "env.GIT_DIFF != ''"
run: make lint
37 changes: 26 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ name: Tests
on:
pull_request:
push:
branches:
- master

jobs:
Cleanup-runs:
Expand All @@ -14,21 +12,38 @@ jobs:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"
if: "!startsWith(github.ref, 'refs/tags/') && !startsWith(github.ref, 'refs/tags/cosmos')"

Unit-tests:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Setup Go 🧰
uses: actions/setup-go@v5
with:
go-version: 1.19
- name: Test & Create coverage report
run: make install test-unit stop-docker-test
- name: Upload cove coverage
uses: codecov/codecov-action@v3

- name: Compute diff 📜
uses: technote-space/[email protected]
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- name: Build 🔨
if: "env.GIT_DIFF != ''"
run: make build

- name: Test & Coverage report creation 🧪
run: make test-unit stop-docker-test

- name: Upload coverage 📤
if: "env.GIT_DIFF != ''"
uses: codecov/[email protected]
with:
file: ./coverage.txt
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ linters:
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- gocritic
- gofmt
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Unreleased
- ([\#702](https://github.com/forbole/bdjuno/pull/702)) Add `message_type` module and store msg types inside `message_type` table, add `messages_by_type` function to allow to query messages by their types

### Changes

#### CI
Expand All @@ -20,7 +22,8 @@
- ([\#489](https://github.com/forbole/bdjuno/pull/489)) Remove block height foreign key from proposal_vote and proposal_deposit tables and add column timestamp
- ([\#499](https://github.com/forbole/bdjuno/pull/499)) Check if proposal has passed voting end time before marking it invalid
- ([\#523](https://github.com/forbole/bdjuno/pull/523)) Update proposal snapshots handling on block

- ([\#681](https://github.com/forbole/bdjuno/pull/681)) Handle proposal status change from deposit to voting
-
#### Daily refetch
- ([\#454](https://github.com/forbole/bdjuno/pull/454)) Added `daily refetch` module to refetch missing blocks every day

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.cosmwasm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


FROM golang:1.18-alpine AS builder
FROM golang:1.19-alpine AS builder
RUN apk update && apk add --no-cache make git
WORKDIR /go/src/github.com/forbole/bdjuno
COPY . ./
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.default
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18-alpine AS builder
FROM golang:1.19-alpine AS builder
RUN apk update && apk add --no-cache make git
WORKDIR /go/src/github.com/forbole/bdjuno
COPY . ./
Expand Down
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,25 @@ test-unit: start-docker-test
@go test -mod=readonly -v -coverprofile coverage.txt ./...
.PHONY: test-unit

###############################################################################
### Linting ###
###############################################################################
golangci_lint_cmd=github.com/golangci/golangci-lint/cmd/golangci-lint

lint:
golangci-lint run --out-format=tab
@echo "--> Running linter"
@go run $(golangci_lint_cmd) run --timeout=10m

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0
@echo "--> Running linter"
@go run $(golangci_lint_cmd) run --fix --out-format=tab --issues-exit-code=0

.PHONY: lint lint-fix

format:
find . -name '*.go' -type f -not -path "*.git*" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "*.git*" | xargs misspell -w
find . -name '*.go' -type f -not -path "*.git*" | xargs goimports -w -local github.com/forbole/bdjuno
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*_mocks.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*_mocks.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*_mocks.go' | xargs goimports -w -local github.com/forbole/bdjuno
.PHONY: format

clean:
Expand Down
2 changes: 2 additions & 0 deletions cmd/migrate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"github.com/spf13/cobra"

v3 "github.com/forbole/bdjuno/v4/cmd/migrate/v3"
v5 "github.com/forbole/bdjuno/v4/cmd/migrate/v5"
)

type Migrator func(parseCfg *parsecmdtypes.Config) error

var (
migrations = map[string]Migrator{
"v3": v3.RunMigration,
"v5": v5.RunMigration,
}
)

Expand Down
43 changes: 43 additions & 0 deletions cmd/migrate/v5/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v5

import (
"fmt"

v5db "github.com/forbole/bdjuno/v4/database/migrate/v5"
parse "github.com/forbole/juno/v5/cmd/parse/types"
"github.com/forbole/juno/v5/database"
"github.com/forbole/juno/v5/database/postgresql"
"github.com/forbole/juno/v5/types/config"
)

// RunMigration runs the migrations to v5
func RunMigration(parseConfig *parse.Config) error {
cfg, err := GetConfig()
if err != nil {
return fmt.Errorf("error while reading config: %s", err)
}

// Migrate the database
err = migrateDb(cfg, parseConfig)
if err != nil {
return fmt.Errorf("error while migrating database: %s", err)
}

return nil
}

func migrateDb(cfg config.Config, parseConfig *parse.Config) error {
// Build the codec
encodingConfig := parseConfig.GetEncodingConfigBuilder()()

// Get the db
databaseCtx := database.NewContext(cfg.Database, &encodingConfig, parseConfig.GetLogger())
db, err := postgresql.Builder(databaseCtx)
if err != nil {
return fmt.Errorf("error while building the db: %s", err)
}

// Build the migrator and perform the migrations
migrator := v5db.NewMigrator(db.(*postgresql.Database))
return migrator.Migrate()
}
29 changes: 29 additions & 0 deletions cmd/migrate/v5/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package v5

import (
"fmt"
"os"
"path"

"github.com/forbole/juno/v5/types/config"
"gopkg.in/yaml.v3"
)

// GetConfig returns the configuration reading it from the config.yaml file present inside the home directory
func GetConfig() (config.Config, error) {
file := path.Join(config.HomePath, "config.yaml")

// Make sure the path exists
if _, err := os.Stat(file); os.IsNotExist(err) {
return config.Config{}, fmt.Errorf("config file does not exist")
}

bz, err := os.ReadFile(file)
if err != nil {
return config.Config{}, fmt.Errorf("error while reading config file: %s", err)
}

var cfg config.Config
err = yaml.Unmarshal(bz, &cfg)
return cfg, err
}
2 changes: 1 addition & 1 deletion database/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ func (db *Db) GetAccounts() ([]string, error) {
var rows []string
err := db.Sqlx.Select(&rows, `SELECT address FROM account`)
return rows, err
}
}
4 changes: 4 additions & 0 deletions database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (suite *DbTestSuite) SetupTest() {
// Build the database
dbCfg := dbconfig.NewDatabaseConfig(
"postgresql://bdjuno:password@localhost:6433/bdjuno?sslmode=disable&search_path=public",
"",
"",
"",
"",
-1,
-1,
100000,
Expand Down
2 changes: 1 addition & 1 deletion database/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (suite *DbTestSuite) encodeProposalContent(content govtypes.Content) string
anyContent, err := codectypes.NewAnyWithValue(protoContent)
suite.Require().NoError(err)

contentBz, err := suite.database.EncodingConfig.Marshaler.MarshalJSON(anyContent)
contentBz, err := suite.database.Cdc.MarshalJSON(anyContent)
suite.Require().NoError(err)

return string(contentBz)
Expand Down
16 changes: 16 additions & 0 deletions database/message_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package database

import (
types "github.com/forbole/bdjuno/v4/types"
)

// SaveMessageType stores the given message type inside the database
func (db *Db) SaveMessageType(msg *types.MessageType) error {
stmt := `
INSERT INTO message_type(type, module, label, height)
VALUES ($1, $2, $3, $4)
ON CONFLICT (type) DO NOTHING`

_, err := db.SQL.Exec(stmt, msg.Type, msg.Module, msg.Label, msg.Height)
return err
}
Loading

0 comments on commit b1e0e26

Please sign in to comment.