Skip to content

Commit

Permalink
Merge pull request #1 from boogeroccam/feat/python-tests
Browse files Browse the repository at this point in the history
Feat/python tests
  • Loading branch information
boogeroccam authored Nov 16, 2024
2 parents d2b350a + bb91a44 commit 6398d49
Show file tree
Hide file tree
Showing 98 changed files with 19,083 additions and 142 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI/CD Pipeline

on:
push:
branches:
- "*"
pull_request:
types: [opened, synchronize]
workflow_dispatch:
inputs:
branch:
description: "Branch to run tests on"
required: true
default: "main"
release:
types: [created]

jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set GO_VERSION
run: echo "GO_VERSION=$(cat go.mod | grep '^go ' | cut -f2 -d' ')" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Build binary
run: make build

- name: Upload binary artifact
# if: github.event_name == 'release'
uses: actions/upload-artifact@v4
with:
name: galacticad
path: build/galacticad

test:
runs-on: self-hosted
needs:
- build
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download binary artifact
uses: actions/download-artifact@v4
with:
name: galacticad
path: build

- uses: astral-sh/setup-uv@v3
with:
version: "latest"

- name: Run tests
run: |
make test
if [ -f "tests/galacli/report.md" ]; then
echo "<details><summary>Test Report</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat tests/galacli/report.md >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
fi
- name: Render the report to the PR when tests fail
uses: marocchino/sticky-pull-request-comment@v2
with:
header: test-report
recreate: true
path: tests/galacli/report.md

permissions:
pull-requests: write
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/make -f

VERSION ?= $(shell echo $(shell git describe --tags `git rev-list --tags="v*" --max-count=1`) | sed 's/^v//')
VERSION ?= $(shell echo $(shell git describe --tags `git rev-list --tags="v*" --max-count=1 2>/dev/null`) 2>/dev/null | sed 's/^v//')
TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')
COMMIT ?= $(shell git log -1 --format='%H' 2>/dev/null )
LEDGER_ENABLED ?= true
GALACTICA_BINARY = galacticad
BUILDDIR ?= $(CURDIR)/build
Expand All @@ -19,7 +19,7 @@ default_target: all

# process build tags

build_tags = netgo
build_tags = netgo objstore
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
Expand Down Expand Up @@ -127,7 +127,7 @@ build-alpine:
@GOOS=linux CGO_ENABLED=1 go build -ldflags="-w -s" -o $(BUILDDIR)/$(GALACTICA_BINARY) ./cmd/galacticad

localnet-build:
@make build
@$(MAKE) build
@echo "Build docker image for localnet..."
@./localnet/build-docker.sh

Expand All @@ -144,3 +144,11 @@ install: build
mkdir -p $(BINDIR)
cp -f $(BUILDDIR)/$(GALACTICA_BINARY) $(BINDIR)/$(GALACTICA_BINARY)
@echo "Galactica has been installed to $(BINDIR)"

help: ## Show this help
@printf "\033[33m%s:\033[0m\n" 'Available commands'
@awk 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:punct:]]+:.*?## / {printf " \033[32m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

ifeq ($(CI),true)
include tests/Makefile
endif
24 changes: 23 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/ethereum/go-ethereum/common"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -136,6 +137,9 @@ import (

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
memiavlstore "github.com/crypto-org-chain/cronos/store"
"github.com/cosmos/cosmos-sdk/client/flags"
evmante "github.com/evmos/ethermint/app/ante"
)

const (
Expand Down Expand Up @@ -234,6 +238,8 @@ type App struct {
txConfig client.TxConfig
interfaceRegistry codectypes.InterfaceRegistry

pendingTxListeners []evmante.PendingTxListener

// non depinject support modules store keys
keys map[string]*storetypes.KVStoreKey
okeys map[string]*storetypes.ObjectStoreKey
Expand Down Expand Up @@ -397,6 +403,9 @@ func New(
// }
// baseAppOptions = append(baseAppOptions, prepareOpt)

homePath := cast.ToString(appOpts.Get(flags.FlagHome))
baseAppOptions = memiavlstore.SetupMemIAVL(logger, homePath, appOpts, false, false, 0, baseAppOptions)

app.App = appBuilder.Build(db, traceStore, baseAppOptions...)

encConfig := MakeEncodingConfig()
Expand Down Expand Up @@ -703,6 +712,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64) {
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
},
PendingTxListener: app.onPendingTx,
})
if err != nil {
panic(err)
Expand All @@ -724,8 +734,9 @@ func initParamsKeeper(

func (app *App) applyUpgrades() {
app.applyUpgrade_v0_1_2()
app.applyUpgrade_v0_2_2()
app.applyUpgrade_v0_2_4()
// app.applyUpgrade_v0_2_3()
app.applyUpgrade_v0_2_7()
}

// AutoCliOpts returns the autocli options for the app.
Expand All @@ -747,3 +758,14 @@ func (app *App) AutoCliOpts() autocli.AppOptions {
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}
}

// RegisterPendingTxListener is used by json-rpc server to listen to pending transactions callback.
func (app *App) RegisterPendingTxListener(listener evmante.PendingTxListener) {
app.pendingTxListeners = append(app.pendingTxListeners, listener)
}

func (app *App) onPendingTx(hash common.Hash) {
for _, listener := range app.pendingTxListeners {
listener(hash)
}
}
43 changes: 43 additions & 0 deletions app/upgrade_v0_2_4.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,46 @@ func (app *App) upgradeHandler_v0_2_4() func(ctx context.Context, _ upgradetypes
return vm, err
}
}

// for andromeda
const (
planName_0_2_2 = "0.2.2"
)

func (app *App) applyUpgrade_v0_2_2() {
app.UpgradeKeeper.SetUpgradeHandler(planName_0_2_2, app.upgradeHandler_v0_2_2())
}

func (app *App) upgradeHandler_v0_2_2() func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
logger := sdk.UnwrapSDKContext(ctx).Logger()

logger.Info("Starting module migrations...")

vm, err := app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
if err != nil {
return vm, err
}

logger.Info("Upgrade " + plan.Name + " complete")

return vm, err
}
}


// solve 0.1.2 update problem on andromeda
const (
planName_0_2_7 = "0.2.7"
)

func (app *App) applyUpgrade_v0_2_7() {
app.UpgradeKeeper.SetUpgradeHandler(planName_0_2_7, app.upgradeHandler_v0_2_7())
}

func (app *App) upgradeHandler_v0_2_7() func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
sdk.UnwrapSDKContext(ctx).Logger().Info("Upgrade " + plan.Name + " complete")
return fromVM, nil
}
}
17 changes: 17 additions & 0 deletions cmd/galacticad/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,20 @@ func VerifyAddressFormat(bz []byte) error {

return nil
}

type VersionDBConfig struct {
// Enable defines if the versiondb should be enabled.
Enable bool `mapstructure:"enable"`
}

func DefaultVersionDBConfig() VersionDBConfig {
return VersionDBConfig{
Enable: false,
}
}

var DefaultVersionDBTemplate = `
[versiondb]
# Enable defines if the versiondb should be enabled.
enable = {{ .VersionDB.Enable }}
`
21 changes: 15 additions & 6 deletions cmd/galacticad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ import (

// ethertypes "github.com/evmos/ethermint/types"

"github.com/Galactica-corp/galactica/app"
authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
txsign "github.com/cosmos/cosmos-sdk/types/tx/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"slices"

confixcmd "cosmossdk.io/tools/confix/cmd"
"github.com/Galactica-corp/galactica/app"
appparams "github.com/Galactica-corp/galactica/app/params"
"github.com/Galactica-corp/galactica/cmd/galacticad/cmd/ethkeys"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/client/pruning"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
txsign "github.com/cosmos/cosmos-sdk/types/tx/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
memiavlcfg "github.com/crypto-org-chain/cronos/store/config"
evmenc "github.com/evmos/ethermint/encoding"
confixcmd "cosmossdk.io/tools/confix/cmd"
)

// NewRootCmd creates a new root command for a Cosmos SDK application
Expand Down Expand Up @@ -229,6 +232,7 @@ func initRootCmd(

rootCmd.AddCommand(
snapshot.Cmd(a.newApp),
pruning.Cmd(a.newApp, app.DefaultNodeHome),
)

rootCmd, err := srvflags.AddGlobalFlags(rootCmd)
Expand Down Expand Up @@ -431,6 +435,9 @@ func initAppConfig() (string, interface{}) {

type CustomAppConfig struct {
ethermintconfig.Config

MemIAVL memiavlcfg.MemIAVLConfig `mapstructure:"memiavl"`
VersionDB VersionDBConfig `mapstructure:"versiondb"`
}

// Optionally allow the chain developer to overwrite the SDK's default
Expand All @@ -452,7 +459,9 @@ func initAppConfig() (string, interface{}) {
srvCfg.JSONRPC.API = ethermintconfig.GetAPINamespaces()

customAppConfig := CustomAppConfig{
Config: *srvCfg,
Config: *srvCfg,
MemIAVL: memiavlcfg.DefaultMemIAVLConfig(),
VersionDB: DefaultVersionDBConfig(),
}
customAppTemplate := serverconfig.DefaultConfigTemplate + ethermintconfig.DefaultConfigTemplate

Expand Down
Loading

0 comments on commit 6398d49

Please sign in to comment.