Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workflows #24

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Compile And Test
on:
push:
branches:
- "**"
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/sagaxyz/*
steps:
- name: Set up access to private Go modules
env:
GITHUB_USER: ${{ secrets.GH_USER }}
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
run: git config --global url."https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com"

- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: "./go.mod"
cache: true
- run: go version

- name: Compile
run: make build

- name: Test
run: go test ./...

- name: Happypath
run: |
export PATH=./build/:$PATH
./scripts/ci/prepare-env.sh
./scripts/happypath.sh

- name: Restart
run: |
kill $(pgrep -fi sscd)
sleep 5
rm -rf ~/.ssc/
export PATH=./build/:$PATH
./scripts/ci/prepare-env.sh
./scripts/escrow-chainlet-restart.sh
29 changes: 29 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: golangci-lint
on:
push:
branches:
- '**'
permissions:
contents: read
# Optional: allow read access to pull requests. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/sagaxyz/*
steps:
- name: Set up access to private Go modules
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
GITHUB_USER: ${{ secrets.GH_USER }}
run: git config --global url."https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com"
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: './go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout 600s
45 changes: 45 additions & 0 deletions .github/workflows/gosec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Run Gosec
on:
pull_request:
branches:
- main
- release/**
paths:
- "**/*.go"
- "go.mod"
- "go.sum"
push:
branches:
- main
paths:
- "**/*.go"
- "go.mod"
- "go.sum"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
Gosec:
permissions:
security-events: write

runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v4

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: "-exclude=G101,G107 -exclude-dir=systemtests -no-fail -fmt sarif -out results.sarif ./..."

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
# Path to SARIF file relative to the root of the repository
sarif_file: results.sarif
18 changes: 18 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ShellCheck

on: [push]

permissions:
contents: read
jobs:
shellcheck:
name: Run shellcheck
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/sagaxyz/*
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
env:
SHELLCHECK_OPTS: -e SC2086
5 changes: 1 addition & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
Expand Down Expand Up @@ -634,8 +632,7 @@ func New(
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(ccvprovidertypes.RouterKey, ccvprovider.NewProviderProposalHandler(app.ProviderKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
AddRoute(ccvprovidertypes.RouterKey, ccvprovider.NewProviderProposalHandler(app.ProviderKeeper))
govConfig := govtypes.DefaultConfig()
app.GovKeeper = govkeeper.NewKeeper(
appCodec,
Expand Down
18 changes: 11 additions & 7 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func init() {

// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of
// an IAVLStore for faster simulation speed.
func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
bapp.SetFauxMerkleMode()
}
// func fauxMerkleModeOpt(bapp *baseapp.BaseApp) {
// bapp.SetFauxMerkleMode()
// }

// BenchmarkSimulation run the chain simulation
// Running using starport command:
Expand Down Expand Up @@ -315,9 +315,12 @@ func TestAppImportExport(t *testing.T) {

ctxA := bApp.NewContextLegacy(true, tmproto.Header{Height: bApp.LastBlockHeight()})
ctxB := newApp.NewContextLegacy(true, tmproto.Header{Height: bApp.LastBlockHeight()})
newApp.ModuleManager().InitGenesis(ctxB, bApp.AppCodec(), genesisState)
newApp.StoreConsensusParams(ctxB, exported.ConsensusParams)

if _, err = newApp.ModuleManager().InitGenesis(ctxB, bApp.AppCodec(), genesisState); err != nil {
panic(err)
}
if err = newApp.StoreConsensusParams(ctxB, exported.ConsensusParams); err != nil {
panic(err)
}
fmt.Printf("comparing stores...\n")

storeKeysPrefixes := []storeKeysPrefixes{
Expand Down Expand Up @@ -449,10 +452,11 @@ func TestAppSimulationAfterImport(t *testing.T) {
)
require.Equal(t, app.Name, bApp.Name())

newApp.InitChain(&abci.RequestInitChain{
_, err = newApp.InitChain(&abci.RequestInitChain{
ChainId: config.ChainID,
AppStateBytes: exported.AppState,
})
require.NoError(t, err)

_, _, err = simulation.SimulateFromSeed(
t,
Expand Down
5 changes: 4 additions & 1 deletion cmd/sscd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
set := func(s *pflag.FlagSet, key, val string) {
if f := s.Lookup(key); f != nil {
f.DefValue = val
f.Value.Set(val)
err := f.Value.Set(val)
if err != nil {
panic(err)
}
}
}
for key, val := range defaults {
Expand Down
1 change: 1 addition & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func handler(title string) http.HandlerFunc {
t, _ := httptemplate.ParseFS(template, indexFile)

return func(w http.ResponseWriter, req *http.Request) {
// nolint: errcheck
t.Execute(w, struct {
Title string
URL string
Expand Down
10 changes: 5 additions & 5 deletions scripts/ci/prepare-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

sscd init test --chain-id testchain
cp ./scripts/ci/config/client.toml ~/.ssc/config/
sscd keys add alice
sscd keys add bob
sscd keys add alice > /dev/null 2>&1
sscd keys add bob > /dev/null 2>&1
sscd add-genesis-account "$(sscd keys show alice -a)" 100000000000000000000000000utsaga,100000000stake
sscd add-genesis-account "$(sscd keys show bob -a)" 100000000000000000000000000utsaga,100000000stake
jq '.app_state["chainlet"]["params"]["chainletStackProtections"]=true' ~/.ssc/config/genesis.json > ~/.ssc/config/tmp_genesis.json && mv ~/.ssc/config/tmp_genesis.json ~/.ssc/config/genesis.json
jq '.app_state["chainlet"]["params"]["nEpochDeposit"]="30"' ~/.ssc/config/genesis.json > ~/.ssc/config/tmp_genesis.json && mv ~/.ssc/config/tmp_genesis.json ~/.ssc/config/genesis.json
jq '.app_state["acl"]["params"]["enable"]=true' > ~/.ssc/config/tmp_genesis.json ~/.ssc/config/genesis.json && mv ~/.ssc/config/tmp_genesis.json ~/.ssc/config/genesis.json
jq ".app_state[\"acl\"][\"allowed\"]=[{\"format\":1,\"value\":\"$(sscd keys show bob -a)\"}]" ~/.ssc/config/genesis.json > ~/.ssc/config/tmp_genesis.json && mv ~/.ssc/config/tmp_genesis.json ~/.ssc/config/genesis.json
sscd gentx alice 100000000stake --chain-id testchain
sscd collect-gentxs
jq ".app_state[\"acl\"][\"allowed\"]=[\"$(sscd keys show bob -a)\"]" ~/.ssc/config/genesis.json > ~/.ssc/config/tmp_genesis.json && mv ~/.ssc/config/tmp_genesis.json ~/.ssc/config/genesis.json
sscd genesis gentx alice 100000000stake --chain-id testchain
sscd genesis collect-gentxs
sscd start &
sleep 10
4 changes: 1 addition & 3 deletions x/billing/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ package keeper_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
testkeeper "github.com/sagaxyz/ssc/testutil/keeper"
"github.com/sagaxyz/ssc/x/billing/types"
"github.com/stretchr/testify/require"
)

func TestParamsQuery(t *testing.T) {
keeper, ctx := testkeeper.BillingKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
keeper.SetParams(ctx, params)

response, err := keeper.Params(wctx, &types.QueryParamsRequest{})
response, err := keeper.Params(ctx, &types.QueryParamsRequest{})
require.NoError(t, err)
require.Equal(t, &types.QueryParamsResponse{Params: params}, response)
}
10 changes: 4 additions & 6 deletions x/billing/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import (

// BeforeEpochStart is the epoch start hook.
func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
ctxx := sdk.WrapSDKContext(ctx)

stacks, err := k.chainletkeeper.ListChainletStack(ctxx, &chainlettypes.QueryListChainletStackRequest{})
stacks, err := k.chainletkeeper.ListChainletStack(ctx, &chainlettypes.QueryListChainletStackRequest{})
if err != nil {
ctx.Logger().Error("could not list chainlet stacks. Error: " + err.Error())
return cosmossdkerrors.Wrapf(types.ErrInternalFailure, "could not list chainlet stacks. Error: "+err.Error())
return cosmossdkerrors.Wrapf(types.ErrInternalFailure, "could not list chainlet stacks. Error: %s", err.Error())
}

kvs := make(map[string]*chainlettypes.ChainletStack)
Expand All @@ -35,10 +33,10 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN
}
}

chainlets, err := k.chainletkeeper.ListChainlets(ctxx, &chainlettypes.QueryListChainletsRequest{Pagination: &query.PageRequest{Limit: k.chainletkeeper.GetParams(ctx).MaxChainlets}})
chainlets, err := k.chainletkeeper.ListChainlets(ctx, &chainlettypes.QueryListChainletsRequest{Pagination: &query.PageRequest{Limit: k.chainletkeeper.GetParams(ctx).MaxChainlets}})
if err != nil {
ctx.Logger().Error("could not list chainlets. Error: " + err.Error())
return cosmossdkerrors.Wrapf(types.ErrInternalFailure, "could not list chainlets. Error: "+err.Error())
return cosmossdkerrors.Wrapf(types.ErrInternalFailure, "could not list chainlets. Error: %s", err.Error())
}

epochInfo := k.epochskeeper.GetEpochInfo(ctx, epochIdentifier)
Expand Down
3 changes: 1 addition & 2 deletions x/billing/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
keepertest "github.com/sagaxyz/ssc/testutil/keeper"
"github.com/sagaxyz/ssc/x/billing/keeper"
"github.com/sagaxyz/ssc/x/billing/types"
)

func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { //nolint:unused
k, ctx := keepertest.BillingKeeper(t)
return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx)
return keeper.NewMsgServerImpl(*k), ctx
}
4 changes: 1 addition & 3 deletions x/chainlet/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ import (

"github.com/sagaxyz/ssc/x/chainlet/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

func TestParamsQuery(t *testing.T) {
keeper, ctx := testkeeper.ChainletKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
keeper.SetParams(ctx, params)

response, err := keeper.Params(wctx, &types.QueryParamsRequest{})
response, err := keeper.Params(ctx, &types.QueryParamsRequest{})
require.NoError(t, err)
require.Equal(t, &types.QueryParamsResponse{Params: params}, response)
}
2 changes: 1 addition & 1 deletion x/chainlet/keeper/msg_server_launch_chainlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (k msgServer) LaunchChainlet(goCtx context.Context, msg *types.MsgLaunchCha
totalFee := epochfee.Add(setupfee)
err = k.billingKeeper.BillAccount(ctx, totalFee, chainlet, stack.ChainletStack.Fees.EpochLength, "launching chainlet")
if err != nil {
return &types.MsgLaunchChainletResponse{}, cosmossdkerrors.Wrapf(types.ErrBillingFailure, fmt.Sprintf("%v", err))
return &types.MsgLaunchChainletResponse{}, cosmossdkerrors.Wrapf(types.ErrBillingFailure, "failed to bill new account %s", err.Error())
}

// Add as a CCV consumer
Expand Down
4 changes: 1 addition & 3 deletions x/chainlet/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (

"github.com/sagaxyz/ssc/x/chainlet/keeper"
"github.com/sagaxyz/ssc/x/chainlet/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

//nolint:unused
func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
k, ctx := keepertest.ChainletKeeper(t)
return keeper.NewMsgServerImpl(k), sdk.WrapSDKContext(ctx)
return keeper.NewMsgServerImpl(k), ctx
}
4 changes: 1 addition & 3 deletions x/escrow/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ package keeper_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
testkeeper "github.com/sagaxyz/ssc/testutil/keeper"
"github.com/sagaxyz/ssc/x/escrow/types"
"github.com/stretchr/testify/require"
)

func TestParamsQuery(t *testing.T) {
keeper, ctx := testkeeper.EscrowKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()
keeper.SetParams(ctx, params)

response, err := keeper.Params(wctx, &types.QueryParamsRequest{})
response, err := keeper.Params(ctx, &types.QueryParamsRequest{})
require.NoError(t, err)
require.Equal(t, &types.QueryParamsResponse{Params: params}, response)
}
3 changes: 1 addition & 2 deletions x/escrow/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
keepertest "github.com/sagaxyz/ssc/testutil/keeper"
"github.com/sagaxyz/ssc/x/escrow/keeper"
"github.com/sagaxyz/ssc/x/escrow/types"
)

func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { //nolint:unused
k, ctx := keepertest.EscrowKeeper(t)
return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx)
return keeper.NewMsgServerImpl(*k), ctx
}
Loading
Loading