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

test: setup simapp for testing #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: E2E Test

on:
pull_request

jobs:
build_image:
name: Building Heighliner
runs-on: ubuntu-latest
steps:
- name: Build Docker image
uses: strangelove-ventures/[email protected]
with:
registry: "" # empty registry, image only shared for e2e testing
tag: local # emulate local environment for consistency in interchaintest cases
tar-export-path: autocctp_simapp.tar # export a tarball that can be uploaded as an artifact for the e2e jobs
platform: linux/amd64 # test runner architecture only
git-ref: ${{ github.head_ref }} # source code ref

# Heighliner chains.yaml config
chain: autocctp-simd
dockerfile: cosmos
build-target: make build
build-dir: simapp
binaries: |
- simapp/build/simd

- name: Upload tarball
uses: actions/upload-artifact@v4
with:
name: autocctp_simapp.tar
path: autocctp_simapp.tar

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
coverage.out
/simapp/build
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build:
@echo "🤖 Building simd..."
@cd simapp && make build 1> /dev/null
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider preserving build output and adding error handling.

Redirecting stdout to /dev/null might hide important build information or errors. Consider the following improvements:

  1. Preserve the build output for debugging purposes.
  2. Add error handling to stop the build process if make build fails.

Here's a suggested improvement:

-	@cd simapp && make build 1> /dev/null
+	@cd simapp && make build || (echo "❌ Build failed" && exit 1)

This change will display the build output and stop the process if make build fails, providing better visibility and error handling.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@cd simapp && make build 1> /dev/null
@cd simapp && make build || (echo "❌ Build failed" && exit 1)

@echo "✅ Completed build!"
204 changes: 113 additions & 91 deletions go.mod

Large diffs are not rendered by default.

997 changes: 618 additions & 379 deletions go.sum

Large diffs are not rendered by default.

537 changes: 537 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ lint:
@go run {{golangci_lint_cmd}} run --timeout=10m
@echo "✅ Completed linting!"

###############################################################################
### Build ###
###############################################################################

# Build the simapp binary
build:
@echo "🤖 Building simd..."
@cd simapp && just build
@echo "✅ Completed build!"

###############################################################################
### Testing ###
Expand Down
18 changes: 9 additions & 9 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
cctpkeeper "github.com/circlefin/noble-cctp/x/cctp/keeper"
cctptypes "github.com/circlefin/noble-cctp/x/cctp/types"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v4/modules/core/exported"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
)

var _ porttypes.IBCModule = &Middleware{}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (m Middleware) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, re

err = m.bankKeeper.SendCoins(
ctx, types.ModuleAddress, feeRecipient,
sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromBigInt(feeAmount.BigInt()))),
sdk.NewCoins(sdk.NewCoin(denom, math.NewIntFromBigInt(feeAmount.BigInt()))),
)
if err != nil {
return channeltypes.NewErrorAcknowledgement(errors.New("failed to execute fee transfer"))
Expand All @@ -124,7 +124,7 @@ func (m Middleware) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, re

err = m.bankKeeper.SendCoins(
ctx, types.ModuleAddress, sender,
sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromBigInt(amount.BigInt()))),
sdk.NewCoins(sdk.NewCoin(denom, math.NewIntFromBigInt(amount.BigInt()))),
)
if err != nil {
return channeltypes.NewErrorAcknowledgement(err)
Expand Down Expand Up @@ -168,7 +168,7 @@ func (m Middleware) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, re

err = m.bankKeeper.SendCoins(
ctx, types.ModuleAddress, feeRecipient,
sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromBigInt(feeAmount.BigInt()))),
sdk.NewCoins(sdk.NewCoin(denom, math.NewIntFromBigInt(feeAmount.BigInt()))),
)
if err != nil {
return channeltypes.NewErrorAcknowledgement(errors.New("failed to execute fee transfer"))
Expand All @@ -180,7 +180,7 @@ func (m Middleware) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, re

err = m.bankKeeper.SendCoins(
ctx, types.ModuleAddress, sender,
sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromBigInt(amount.BigInt()))),
sdk.NewCoins(sdk.NewCoin(denom, math.NewIntFromBigInt(amount.BigInt()))),
)
if err != nil {
return channeltypes.NewErrorAcknowledgement(err)
Expand Down
27 changes: 27 additions & 0 deletions simapp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')

ifeq (,$(VERSION))
VERSION := $(shell git describe --exact-match 2>/dev/null)
ifeq (,$(VERSION))
ifeq ($(shell git status --porcelain),)
VERSION := $(BRANCH)
else
VERSION := $(BRANCH)-dirty
endif
endif
endif

ldflags := $(LDFLAGS)
ldflags += -X github.com/cosmos/cosmos-sdk/version.Name=simapp \
-X github.com/cosmos/cosmos-sdk/version.AppName=simd \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -ldflags '$(ldflags)'

build:
@go build -mod=readonly $(BUILD_FLAGS) -o $(PWD)/build/ ./...

.PHONY: build
68 changes: 68 additions & 0 deletions simapp/ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package app

import (
errorsmod "cosmossdk.io/errors"
"github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory"
ftfkeeper "github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory/keeper"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
)

// HandlerOptions extends the options required by the default Cosmos SDK
// AnteHandler for our custom ante decorators.
type HandlerOptions struct {
ante.HandlerOptions
cdc codec.Codec
FTFKeeper *ftfkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
Comment on lines +19 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation for options.cdc

The options.cdc field is used in fiattokenfactory.NewIsPausedDecorator, but there is no validation to ensure it is not nil. This could lead to a nil pointer dereference at runtime.

Add a validation check for options.cdc:

+	if options.cdc == nil {
+		return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "codec is required for ante builder")
+	}

Place this validation after the existing checks for other required fields.

Committable suggestion was skipped due to low confidence.

}

// NewAnteHandler extends the default Cosmos SDK AnteHandler with custom ante decorators.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}

if options.FTFKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "fiattokenfactory keeper is required for ante builder")
}

if options.IBCKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "ibc keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),

fiattokenfactory.NewIsPausedDecorator(options.cdc, options.FTFKeeper),
fiattokenfactory.NewIsBlacklistedDecorator(options.FTFKeeper),

ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),

ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
}
Loading