diff --git a/.github/release-drafter-config.yaml b/.github/release-drafter-config.yaml deleted file mode 100644 index 94ca09aa..00000000 --- a/.github/release-drafter-config.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name-template: 'v$RESOLVED_VERSION' -tag-template: 'v$RESOLVED_VERSION' -categories: - - title: 'šŸš€ Features' - label: 'enhancement' - label: 'feature' - - - title: 'āš™ļø Fixes' - label: 'fix' - label: 'bug' - label: 'hotfix' - - - title: 'Dependency upgrades (Tendermint, Cosmos SDK, EvmOS, etc)' - label: 'dependency' - -change-template: '- $TITLE @$AUTHOR (#$NUMBER)' -change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. -version-resolver: - major: - labels: - - 'major' - minor: - labels: - - 'minor' - patch: - labels: - - 'patch' - default: patch -template: | - ## EFFECTS - - - [ ] Soft update - - [ ] Chain fork related - - ## CHANGES - - $CHANGES \ No newline at end of file diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 05423359..e6857639 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -1,4 +1,4 @@ -name: Integration test +name: End-to-end test on: push: @@ -17,17 +17,17 @@ jobs: - name: Setup network run: | mkdir ~/genesis - cd integration_test && docker-compose up -d + cd tests/e2e && docker-compose up -d docker ps sleep 20 - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.18.x + go-version: 1.19.x - - name: Integration test - run: cd integration_test && go test + - name: End-to-end test + run: cd tests/e2e && go test - name: Teardown - run: cd integration_test && docker-compose down + run: cd tests/e2e && docker-compose down diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml deleted file mode 100644 index 2eed5bac..00000000 --- a/.github/workflows/release-drafter.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: Release Drafter -on: - push: - branches: [ "main", "cube", "tesseract" ] - -jobs: - update_release_draft: - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@v5 - - with: - config-name: release-drafter-config.yml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..dddcbe1a --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,117 @@ +name: "Release" + +on: + # can be used to re-release an existing tag + workflow_dispatch: + + push: + tags: + - "v[0-9]+\\.[0-9]+\\.[0-9]+" + - "v[0-9]+\\.[0-9]+\\.[0-9]+-*" + +jobs: + release: + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - name: Create release for ${{ github.ref_name }} + run: gh release create ${{ github.ref_name }} --prerelease --generate-notes --repo ${{ github.repository }} + + + artifacts: + if: startsWith(github.ref, 'refs/tags/') + needs: release + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + strategy: + matrix: + build_type: ['build-release-arm64', 'build-release-amd64'] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set version tag + run: echo "VERSION=$(echo ${{ github.ref_name }} | sed 's/^v//')" >> $GITHUB_ENV + - name: Create build directory + run: mkdir -p build/release + - name: Build ${{ matrix.build_type }} + run: make ${{ matrix.build_type }} + - name: Upload the artifacts to release + run: gh release upload ${{ github.ref_name }} ./build/release/* + + calculate-checksums: + needs: artifacts + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - name: Create build directory + run: mkdir -p build/release + - name: Download artifacts + run: gh release download ${{ github.ref_name }} --pattern '*.tar.gz' --dir build/release --repo ${{ github.repository }} + - name: Create checksums + run: | + cd build/release + sha256sum *.tar.gz > checksum.txt + - name: Display checksums + run: cat build/release/checksum.txt + - name: Upload the checksum to release + run: gh release upload ${{github.ref_name}} build/release/checksum.txt --repo ${{github.repository}} + + generate-json: + needs: calculate-checksums + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + - name: Create build directory + run: mkdir -p build/release + - name: Download artifacts + run: gh release download ${{github.ref_name}} --pattern '*.tar.gz' --dir build/release --repo ${{github.repository}} + - name: Generate JSON file + run: | + cd build/release + binaries=() + for file in *.tar.gz; do + checksum=$(sha256sum $file | awk '{print $1}') + url="https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/$file?checksum=sha256:$checksum" + declare -A TRANSLATION_MATRIX + TRANSLATION_MATRIX=( ["Linux_x86_64"]="linux/amd64" ["Linux_arm64"]="linux/arm64" ["Darwin_arm64"]="darwin/arm64" ) + os_architecture_translated="" + for key in "${!TRANSLATION_MATRIX[@]}"; do + if [[ "$file" == *"$key"* ]]; then + os_architecture_translated="${TRANSLATION_MATRIX[$key]}" + break + fi + done + if [ -z "$os_architecture_translated" ] + then + echo "Could not translate OS and architecture information from binary name: $file" + exit 1 + fi + binaries+=(" \"$os_architecture_translated\": \"$url\"") + done + binaries_json=$(IFS=$',\n'; echo "${binaries[*]}") + cat << EOF > binaries.json.raw + { + "binaries": { + $binaries_json + } + } + EOF + + - name: Pretty-print JSON file using jq + run: | + cd build/release + jq . < binaries.json.raw > binaries.json && rm binaries.json.raw + + - name: Display JSON file + run: cat build/release/binaries.json + - name: Upload the JSON file to release + run: gh release upload ${{ github.ref_name }} build/release/binaries.json --repo ${{ github.repository }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 63868525..04bb2bb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,41 +8,37 @@ ### BUILD FROM golang:1.19-alpine AS build -WORKDIR /localnet # Create appuser. RUN adduser -D -g '' valiuser # Install required binaries RUN apk add --update --no-cache zip git make cmake build-base linux-headers musl-dev libc-dev -# Copy source files -COPY . /localnet/ - -ENV LIBWASMVM_VERSION=v1.3.0 - +WORKDIR / RUN git clone --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install ENV MIMALLOC_RESERVE_HUGE_OS_PAGES=4 -# See https://github.com/CosmWasm/wasmvm/releases -ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASMVM_VERSION}/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a -ADD https://github.com/CosmWasm/wasmvm/releases/download/${LIBWASMVM_VERSION}/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a -RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep b1610f9c8ad8bdebf5b8f819f71d238466f83521c74a2deb799078932e862722 -RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep b4aad4480f9b4c46635b4943beedbb72c929eab1d1b9467fe3b43e6dbf617e32 -# Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc` -RUN cp /lib/libwasmvm_muslc.`uname -m`.a /lib/libwasmvm_muslc.a +WORKDIR /workspace +# Copy source files +COPY . . +# Download dependencies and CosmWasm libwasmvm if found. +RUN set -eux; \ + export ARCH=$(uname -m); \ + WASM_VERSION=$(go list -mod=readonly -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}'); \ + if [ ! -z "${WASM_VERSION}" ]; then \ + wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \ + fi; \ + go mod download; # Build executable -RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS='-linkmode=external -extldflags "-L/localnet/mimalloc/build -lmimalloc -Wl,-z,muldefs -static"' make build +RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS='-linkmode=external -extldflags "-L/mimalloc/build -lmimalloc -Wl,-z,muldefs -static"' make build # -------------------------------------------------------- -FROM alpine:3.15 AS runtime - -WORKDIR /opt -RUN [ "mkdir", "-p", "/opt/integration_test" ] +FROM alpine:3.18 AS runtime -COPY --from=build /localnet/build/xplad /usr/bin/xplad -COPY --from=build /localnet/integration_test /opt/integration_test +COPY --from=build /workspace/build/xplad /usr/bin/xplad +COPY --from=build /workspace/tests/e2e /opt/tests/e2e # Expose Cosmos ports EXPOSE 9090 diff --git a/Makefile b/Makefile index 5c52d6b7..02dc3db7 100644 --- a/Makefile +++ b/Makefile @@ -16,9 +16,12 @@ NAME := xpla APPNAME := xplad LEDGER_ENABLED ?= true TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7" +BUILDDIR ?= $(CURDIR)/build +GO_VERSION ?= "1.19" # for dockerized protobuf tools DOCKER := $(shell which docker) +DOCKER_COMPOSE := $(shell which docker-compose) BUF_IMAGE=bufbuild/buf@sha256:3cb1f8a4b48bd5ad8f09168f10f607ddc318af202f5c057d52a45216793d85e5 #v1.4.0 DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(BUF_IMAGE) @@ -87,12 +90,56 @@ endif all: install +.PHONY: install install: go.sum go install -mod=readonly $(BUILD_FLAGS) ./cmd/xplad +.PHONY: build build: go.sum go build -mod=readonly $(BUILD_FLAGS) -o build/xplad ./cmd/xplad +build-release: build/linux/amd64 build/linux/arm64 + +build-release-amd64: go.sum $(BUILDDIR)/ + $(DOCKER) buildx create --name xpla-builder || true + $(DOCKER) buildx use xpla-builder + $(DOCKER) buildx build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + --build-arg GOOS=linux \ + --build-arg GOARCH=amd64 \ + --platform linux/amd64 \ + -t xpla:local-amd64 \ + --load \ + -f Dockerfile . + $(DOCKER) rm -f xpla-builder || true + $(DOCKER) create -ti --name xpla-builder xpla:local-amd64 + $(DOCKER) cp xpla-builder:/usr/bin/xplad $(BUILDDIR)/release/xplad + tar -czvf $(BUILDDIR)/release/xpla_$(VERSION)_Linux_x86_64.tar.gz -C $(BUILDDIR)/release/ xplad + rm $(BUILDDIR)/release/xplad + $(DOCKER) rm -f xpla-builder + +build-release-arm64: go.sum $(BUILDDIR)/ + $(DOCKER) buildx create --name xpla-builder || true + $(DOCKER) buildx use xpla-builder + $(DOCKER) buildx build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + --build-arg GOOS=linux \ + --build-arg GOARCH=arm64 \ + --platform linux/arm64 \ + -t xpla:local-arm64 \ + --load \ + -f Dockerfile . + $(DOCKER) rm -f xpla-builder || true + $(DOCKER) create -ti --name xpla-builder xpla:local-arm64 + $(DOCKER) cp xpla-builder:/usr/bin/xplad $(BUILDDIR)/release/xplad + tar -czvf $(BUILDDIR)/release/xpla_$(VERSION)_Linux_arm64.tar.gz -C $(BUILDDIR)/release/ xplad + rm $(BUILDDIR)/release/xplad + $(DOCKER) rm -f xpla-builder + .PHONY: test test: go.sum go test -short ./... diff --git a/app/app.go b/app/app.go index 8790b8dc..d70d2d32 100644 --- a/app/app.go +++ b/app/app.go @@ -58,6 +58,7 @@ import ( "github.com/xpladev/xpla/docs" evmupgrade "github.com/xpladev/xpla/app/upgrades/evm" + "github.com/xpladev/xpla/app/upgrades/v1_4" "github.com/xpladev/xpla/app/upgrades/volunteer" xplareward "github.com/xpladev/xpla/app/upgrades/xpla_reward" ) @@ -422,6 +423,12 @@ func (app *XplaApp) setUpgradeHandlers() { volunteer.CreateUpgradeHandler(app.mm, app.configurator, &app.AppKeepers), ) + // v1_4 upgrade handler + app.UpgradeKeeper.SetUpgradeHandler( + v1_4.UpgradeName, + v1_4.CreateUpgradeHandler(app.mm, app.configurator, app.AppKeepers.AccountKeeper, &app.AppKeepers.StakingKeeper), + ) + // When a planned update height is reached, the old binary will panic // writing on disk the height and name of the update that triggered it // This will read that value, and execute the preparations for the upgrade. @@ -449,6 +456,9 @@ func (app *XplaApp) setUpgradeHandlers() { storeUpgrades = &storetypes.StoreUpgrades{ Added: volunteer.AddModules, } + case v1_4.UpgradeName: + storeUpgrades = &storetypes.StoreUpgrades{} + } if storeUpgrades != nil { diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 3e5eb96d..1e43aa00 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -43,6 +43,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router" + routerkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/keeper" + routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types" icacontroller "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller" icacontrollerkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/keeper" icacontrollertypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types" @@ -69,9 +72,6 @@ import ( "github.com/evmos/evmos/v9/x/erc20" erc20keeper "github.com/evmos/evmos/v9/x/erc20/keeper" erc20types "github.com/evmos/evmos/v9/x/erc20/types" - "github.com/strangelove-ventures/packet-forward-middleware/v4/router" - routerkeeper "github.com/strangelove-ventures/packet-forward-middleware/v4/router/keeper" - routertypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" tmos "github.com/tendermint/tendermint/libs/os" rewardkeeper "github.com/xpladev/xpla/x/reward/keeper" rewardtypes "github.com/xpladev/xpla/x/reward/types" diff --git a/app/keepers/keys.go b/app/keepers/keys.go index a15b5747..7d287736 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -17,6 +17,7 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types" icacontrollertypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types" ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" @@ -25,7 +26,6 @@ import ( evmtypes "github.com/evmos/ethermint/x/evm/types" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" erc20types "github.com/evmos/evmos/v9/x/erc20/types" - routertypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" rewardtypes "github.com/xpladev/xpla/x/reward/types" volunteertypes "github.com/xpladev/xpla/x/volunteer/types" ) diff --git a/app/modules.go b/app/modules.go index 0113092b..50cbe88c 100644 --- a/app/modules.go +++ b/app/modules.go @@ -35,6 +35,8 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router" + routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types" ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts" icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types" ibcfee "github.com/cosmos/ibc-go/v4/modules/apps/29-fee" @@ -50,8 +52,6 @@ import ( feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" "github.com/evmos/evmos/v9/x/erc20" erc20types "github.com/evmos/evmos/v9/x/erc20/types" - "github.com/strangelove-ventures/packet-forward-middleware/v4/router" - routertypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" xplaparams "github.com/xpladev/xpla/app/params" xplaevm "github.com/xpladev/xpla/x/evm" "github.com/xpladev/xpla/x/reward" diff --git a/app/upgrades/v1_4/const.go b/app/upgrades/v1_4/const.go new file mode 100644 index 00000000..f259d894 --- /dev/null +++ b/app/upgrades/v1_4/const.go @@ -0,0 +1,5 @@ +package v1_4 + +const ( + UpgradeName = "v1_4" +) diff --git a/app/upgrades/v1_4/upgrades.go b/app/upgrades/v1_4/upgrades.go new file mode 100644 index 00000000..3322475f --- /dev/null +++ b/app/upgrades/v1_4/upgrades.go @@ -0,0 +1,74 @@ +package v1_4 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/module" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/ethereum/go-ethereum/common" + etherminttypes "github.com/evmos/ethermint/types" + evmtypes "github.com/evmos/ethermint/x/evm/types" + + stakingkeeper "github.com/xpladev/xpla/x/staking/keeper" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + authKeeper authkeeper.AccountKeeper, + stakingKeeper *stakingkeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + + migrateBaseAccountToEthAccount(ctx, authKeeper) + + err := migrateDustDelegation(ctx, stakingKeeper) + if err != nil { + return nil, err + } + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + +func migrateBaseAccountToEthAccount(ctx sdk.Context, authKeeper authkeeper.AccountKeeper) { + authKeeper.IterateAccounts(ctx, func(acc authtypes.AccountI) (stop bool) { + switch acc := acc.(type) { + case *authtypes.BaseAccount: + ethAcc := ðerminttypes.EthAccount{ + BaseAccount: acc, + CodeHash: common.BytesToHash(evmtypes.EmptyCodeHash).String(), + } + + authKeeper.SetAccount(ctx, ethAcc) + } + + return false + }) +} + +func migrateDustDelegation(ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper) error { + validators := stakingKeeper.GetAllValidators(ctx) + for _, validator := range validators { + tolerance, err := validator.SharesFromTokens(sdk.OneInt()) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrLogic, "validator must have valid share") + } + + delegations := stakingKeeper.GetValidatorDelegations(ctx, validator.GetOperator()) + for _, delegation := range delegations { + if delegation.Shares.GTE(tolerance) { + continue + } + + _, err := stakingKeeper.Unbond(ctx, delegation.GetDelegatorAddr(), validator.GetOperator(), delegation.GetShares()) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrLogic, "dust delegation must be unbond") + } + } + } + + return nil +} diff --git a/app/upgrades/volunteer/upgrades.go b/app/upgrades/volunteer/upgrades.go index e972fbcc..4765a3e7 100644 --- a/app/upgrades/volunteer/upgrades.go +++ b/app/upgrades/volunteer/upgrades.go @@ -4,11 +4,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types" icacontrollertypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types" ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" - routertypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" "github.com/xpladev/xpla/app/keepers" ) diff --git a/cmd/xplad/cmd/root.go b/cmd/xplad/cmd/root.go index 70edeb6e..9a83bb40 100644 --- a/cmd/xplad/cmd/root.go +++ b/cmd/xplad/cmd/root.go @@ -31,6 +31,7 @@ import ( "github.com/spf13/cast" "github.com/spf13/cobra" "github.com/spf13/viper" + tmcmd "github.com/tendermint/tendermint/cmd/cometbft/commands" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -147,6 +148,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { queryCommand(), txCommand(), ethermintclient.KeyCommands(xpla.DefaultNodeHome), + tmcmd.ReIndexEventCmd, ) } diff --git a/go.mod b/go.mod index 2ed486c0..f603e730 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/cosmos/cosmos-proto v1.0.0-beta.2 github.com/cosmos/cosmos-sdk v0.45.16 github.com/cosmos/gogoproto v1.4.6 + github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4 v4.1.1 github.com/cosmos/ibc-go/v4 v4.5.1 github.com/ethereum/go-ethereum v1.10.19 github.com/evmos/ethermint v0.19.3 @@ -21,7 +22,6 @@ require ( github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.14.0 - github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.6 github.com/stretchr/testify v1.8.2 github.com/tendermint/tendermint v0.35.4 github.com/tendermint/tm-db v0.6.7 @@ -39,7 +39,7 @@ require ( filippo.io/edwards25519 v1.0.0-rc.1 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect - github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect + github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect github.com/CosmWasm/wasmvm v1.3.1 // indirect github.com/DataDog/zstd v1.5.0 // indirect github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect @@ -192,7 +192,7 @@ replace ( // TODO: Simapp dependency, review removing when updating to SDK with backported update https://github.com/cosmos/cosmos-sdk/issues/13423 github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 // indirect - github.com/cosmos/cosmos-sdk => github.com/xpladev/cosmos-sdk v0.45.19-xpla + github.com/cosmos/cosmos-sdk => github.com/xpladev/cosmos-sdk v0.45.20-xpla // enforce same SDK and IBC on all dependencies github.com/cosmos/ibc-go/v4 => github.com/cosmos/ibc-go/v4 v4.5.1 @@ -212,6 +212,6 @@ replace ( github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27 + github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.29 google.golang.org/grpc => google.golang.org/grpc v1.33.2 ) diff --git a/go.sum b/go.sum index fe8cc0e7..19da96a8 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= -github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= +github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= +github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw= github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w= @@ -207,8 +207,8 @@ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcju github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA= github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= -github.com/cometbft/cometbft v0.34.27 h1:ri6BvmwjWR0gurYjywcBqRe4bbwc3QVs9KRcCzgh/J0= -github.com/cometbft/cometbft v0.34.27/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw= +github.com/cometbft/cometbft v0.34.29 h1:Q4FqMevP9du2pOgryZJHpDV2eA6jg/kMYxBj9ZTY6VQ= +github.com/cometbft/cometbft v0.34.29/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw= github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= github.com/confio/ics23/go v0.9.1 h1:3MV46eeWwO3xCauKyAtuAdJYMyPnnchW4iLr2bTw6/U= @@ -239,6 +239,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4 github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY= github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4 v4.1.1 h1:TeiMKG56Kg+lqw/+08dfusInebjVagr9v75sP2GJo6w= +github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4 v4.1.1/go.mod h1:mFk2qfXAm7ndXQQuXUGm9tlC2OM9jxPQb5PRKEHNU5I= github.com/cosmos/ibc-go/v4 v4.5.1 h1:+P73X7aIikGAXBUJ9vP9rEbvdSuekt3KGXmAWCSYets= github.com/cosmos/ibc-go/v4 v4.5.1/go.mod h1:2EOi40Bx/j6rJrtP1ui8k8yUAMpGybmL1EjakYqYv5U= github.com/cosmos/interchain-accounts v0.2.6 h1:TV2M2g1/Rb9MCNw1YePdBKE0rcEczNj1RGHT+2iRYas= @@ -969,8 +971,6 @@ github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+eg github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969 h1:Oo2KZNP70KE0+IUJSidPj/BFS/RXNHmKIJOdckzml2E= github.com/status-im/keycard-go v0.0.0-20200402102358-957c09536969/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= -github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.6 h1:aY64yjKZyDyzlIbDOkGBPvVpR0ArzIjunpCRKqoIm7o= -github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.6/go.mod h1:4zAtg449/JISRmf+sbmqolqSLP+QJBh+EtWkWtt/AKE= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= @@ -1046,8 +1046,8 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -github.com/xpladev/cosmos-sdk v0.45.19-xpla h1:d7ZV4ioj+OfHiVsQZvWlyHoPmvVez/7mI0kfDyUc+wo= -github.com/xpladev/cosmos-sdk v0.45.19-xpla/go.mod h1:3MSZtH7mYNdRrybrpw8aJi4lnjQPJgg7Suw9K4fUh/w= +github.com/xpladev/cosmos-sdk v0.45.20-xpla h1:BkogYrm3LgFqbCvJsHI6W9dWPx5YIvLIVSccpgVaXd0= +github.com/xpladev/cosmos-sdk v0.45.20-xpla/go.mod h1:3MSZtH7mYNdRrybrpw8aJi4lnjQPJgg7Suw9K4fUh/w= github.com/xpladev/ethermint v0.19.4-xpla h1:F7SdxazMYXhVz37u4XyyXa4nGZ0ad/g6uifZX+quAvk= github.com/xpladev/ethermint v0.19.4-xpla/go.mod h1:yVEHdlFKDd/ZOfkR30ZCK0yyQ3KufwmTTwvk1IYz6qY= github.com/xpladev/evmos/v9 v9.2.0-xpla h1:UwuEqik0RyEsxMJzlrbE9u+hfmnY1VZXQMfprJebI3U= diff --git a/integration_test/README.md b/integration_test/README.md deleted file mode 100644 index 35da89a6..00000000 --- a/integration_test/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# Integration Test - -This module is basically for the automated integration test. But if you want to execute by yourself for testing (test testing) purpose, this tests are also executable on your local. Please follow the step below: - -## Prerequisites - -- Docker >= 20.10 -- Docker compose >= 2.12 - -## How to run - -```bash -# 1. From the repo root, move to the integration_test, and execute docker compose -cd integration_test -docker-compose up -d - -# 2. Wait for building. Once done without error, you may check the nodes running -docker ps - -#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -#648b7146ce8c integration_test-node1 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 0.0.0.0:8545->8545/tcp, 0.0.0.0:9090->9090/tcp, 0.0.0.0:26656->26656/tcp xpla-localnet-validator1 -#97279d567135 integration_test-node2 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9100->9100/tcp, 26656/tcp, 0.0.0.0:26666->26666/tcp xpla-localnet-validator2 -#f604f68c3f82 integration_test-node3 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9110->9110/tcp, 26656/tcp, 0.0.0.0:26676->26676/tcp xpla-localnet-validator3 -#c3d0d9daefd2 integration_test-node4 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9120->9120/tcp, 26656/tcp, 0.0.0.0:26686->26686/tcp xpla-localnet-validator4 - -# 3. Execute tests -go test - -# Do not execute short mode -# (X) go test -short - -# ... -# PASS -# ok github.com/xpladev/xpla/integration_test 29.365s - -# If you see the pass sign, you may down the nodes -docker-compose down -``` - -## Test scenario - -### WASM - -- Send `delegation` tx -- Upload the contract binary and get a code ID -- With the code ID above, try to instantiate the contract -- Execute the contract -- Assert from querying the contract in each test step by assertion diff --git a/scripts/protoc-swagger-openapi-gen.sh b/scripts/protoc-swagger-openapi-gen.sh index ddddb90a..a2ecce66 100755 --- a/scripts/protoc-swagger-openapi-gen.sh +++ b/scripts/protoc-swagger-openapi-gen.sh @@ -20,7 +20,7 @@ wasm_dir=$(go list -f '{{ .Dir }}' -m github.com/CosmWasm/wasmd) ibc_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/ibc-go/v4) ica=$(go list -f '{{ .Dir }}' -m github.com/cosmos/interchain-accounts) ethermint_dir=$(go list -f '{{ .Dir }}' -m github.com/evmos/ethermint) -pfm=$(go list -f '{{ .Dir }}' -m github.com/strangelove-ventures/packet-forward-middleware/v4) +pfm=$(go list -f '{{ .Dir }}' -m github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4) xpla_dir=$(go list -f '{{ .Dir }}' -m github.com/xpladev/xpla) # move the vendor folder back to ./vendor diff --git a/integration_test/.env b/tests/e2e/.env similarity index 100% rename from integration_test/.env rename to tests/e2e/.env diff --git a/tests/e2e/README.md b/tests/e2e/README.md new file mode 100644 index 00000000..43431ebd --- /dev/null +++ b/tests/e2e/README.md @@ -0,0 +1,48 @@ +# End-to-end Test + +This module is basically for the automated end-to-end test. But if you want to execute by yourself for testing (test testing) purpose, this tests are also executable on your local. Please follow the step below: + +## Prerequisites + +- Docker >= 20.10 +- Docker compose >= 2.12 + +## How to run + +```bash +# 1. From the repo root, move to the tests/e2e, and execute docker compose +cd tests/e2e +docker-compose up -d + +# 2. Wait for building. Once done without error, you may check the nodes running +docker ps + +#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +#648b7146ce8c e2e-node1 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 0.0.0.0:8545->8545/tcp, 0.0.0.0:9090->9090/tcp, 0.0.0.0:26656->26656/tcp xpla-localnet-validator1 +#97279d567135 e2e-node2 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9100->9100/tcp, 26656/tcp, 0.0.0.0:26666->26666/tcp xpla-localnet-validator2 +#f604f68c3f82 e2e-node3 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9110->9110/tcp, 26656/tcp, 0.0.0.0:26676->26676/tcp xpla-localnet-validator3 +#c3d0d9daefd2 e2e-node4 "sh -c 'MONIKER=valiā€¦" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9120->9120/tcp, 26656/tcp, 0.0.0.0:26686->26686/tcp xpla-localnet-validator4 + +# 3. Execute tests +go test + +# Do not execute short mode +# (X) go test -short + +# ... +# PASS +# ok github.com/xpladev/xpla/tests/e2e 29.365s + +# If you see the pass sign, you may down the nodes +docker-compose down +``` + +## Test scenario + +### WASM + +- Send `delegation` tx +- Upload the contract binary and get a code ID +- With the code ID above, try to instantiate the contract +- Execute the contract +- Assert from querying the contract in each test step by assertion diff --git a/integration_test/common_configs/app.toml b/tests/e2e/common_configs/app.toml similarity index 100% rename from integration_test/common_configs/app.toml rename to tests/e2e/common_configs/app.toml diff --git a/integration_test/common_configs/client.toml b/tests/e2e/common_configs/client.toml similarity index 100% rename from integration_test/common_configs/client.toml rename to tests/e2e/common_configs/client.toml diff --git a/integration_test/common_configs/config.toml b/tests/e2e/common_configs/config.toml similarity index 100% rename from integration_test/common_configs/config.toml rename to tests/e2e/common_configs/config.toml diff --git a/integration_test/docker-compose.yml b/tests/e2e/docker-compose.yml similarity index 84% rename from integration_test/docker-compose.yml rename to tests/e2e/docker-compose.yml index fe581e52..3eed63bf 100644 --- a/integration_test/docker-compose.yml +++ b/tests/e2e/docker-compose.yml @@ -4,7 +4,7 @@ services: container_name: xpla-localnet-validator1 build: - context: ../. + context: ../../. target: runtime volumes: @@ -16,7 +16,7 @@ services: - "36656:26656" - "36657:26657" - entrypoint: sh -c "MONIKER=validator1 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_master.sh" + entrypoint: sh -c "MONIKER=validator1 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_master.sh" networks: vpcbr: @@ -32,7 +32,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -40,7 +40,7 @@ services: - "19100:9090" - "36666:26656" - entrypoint: sh -c "MONIKER=validator2 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator2 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -56,7 +56,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -64,7 +64,7 @@ services: - "19110:9090" - "36676:26656" - entrypoint: sh -c "MONIKER=validator3 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator3 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -80,7 +80,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -88,7 +88,7 @@ services: - "19120:9090" - "36686:26656" - entrypoint: sh -c "MONIKER=validator4 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator4 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -104,7 +104,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -112,7 +112,7 @@ services: - "19130:9090" - "36696:26656" - entrypoint: sh -c "MONIKER=validator5_experimental XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator5_experimental XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -128,7 +128,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -136,7 +136,7 @@ services: - "19140:9090" - "36706:26656" - entrypoint: sh -c "MONIKER=volunteer_validator1 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=volunteer_validator1 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -152,7 +152,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -160,7 +160,7 @@ services: - "19150:9090" - "36716:26656" - entrypoint: sh -c "MONIKER=volunteer_validator2 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=volunteer_validator2 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -176,7 +176,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -184,7 +184,7 @@ services: - "19160:9090" - "36726:26656" - entrypoint: sh -c "MONIKER=volunteer_validator3 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=volunteer_validator3 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: diff --git a/integration_test/entrypoint.sh b/tests/e2e/entrypoint.sh similarity index 64% rename from integration_test/entrypoint.sh rename to tests/e2e/entrypoint.sh index 862deb1f..5c6b411b 100644 --- a/integration_test/entrypoint.sh +++ b/tests/e2e/entrypoint.sh @@ -1,16 +1,16 @@ #!/bin/sh -# MONIKER=validator1|validator2|validator3|validator4 sh /opt/integration_test/entrypoint.sh +# MONIKER=validator1|validator2|validator3|validator4 sh /opt/tests/e2e/entrypoint.sh # 1. chain init /usr/bin/xplad init $MONIKER --chain-id localtest_1-1 --home $XPLAHOME # 2. copy the node setting files to the node home dir -cp -r /opt/integration_test/$MONIKER/* /opt/.xpla/config +cp -r /opt/tests/e2e/$MONIKER/* /opt/.xpla/config # 3. register my validator & users keyfile -/usr/bin/xplad keys add validator1 --recover --home $XPLAHOME < /opt/integration_test/test_keys/$MONIKER.mnemonics -/usr/bin/xplad keys add user1 --recover --home $XPLAHOME < /opt/integration_test/test_keys/user1.mnemonics -/usr/bin/xplad keys add user2 --recover --home $XPLAHOME < /opt/integration_test/test_keys/user2.mnemonics +/usr/bin/xplad keys add validator1 --recover --home $XPLAHOME < /opt/tests/e2e/test_keys/$MONIKER.mnemonics +/usr/bin/xplad keys add user1 --recover --home $XPLAHOME < /opt/tests/e2e/test_keys/user1.mnemonics +/usr/bin/xplad keys add user2 --recover --home $XPLAHOME < /opt/tests/e2e/test_keys/user2.mnemonics # 4. check genesis.json /usr/bin/xplad validate-genesis --home $XPLAHOME diff --git a/integration_test/entrypoint_master.sh b/tests/e2e/entrypoint_master.sh similarity index 84% rename from integration_test/entrypoint_master.sh rename to tests/e2e/entrypoint_master.sh index 28f41f53..e6d1f505 100644 --- a/integration_test/entrypoint_master.sh +++ b/tests/e2e/entrypoint_master.sh @@ -1,5 +1,5 @@ #!/bin/sh -# MONIKER=validator1|validator2|validator3|validator4 sh /opt/integration_test/entrypoint.sh +# MONIKER=validator1|validator2|validator3|validator4 sh /opt/tests/e2e/entrypoint.sh # File is not atomic and somestimes secondary nodes copies the existing old genesisfile # It should be cleared @@ -10,25 +10,25 @@ rm -f /genesis/* # 2. Register the keys # xpla1z2k85n48ydfvzslrugwzl4j2u7vtdyf3xvucmc -/usr/bin/xplad keys add validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator1.mnemonics +/usr/bin/xplad keys add validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator1.mnemonics # xpla16wx7ye3ce060tjvmmpu8lm0ak5xr7gm2dp0kpt -/usr/bin/xplad keys add validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator2.mnemonics +/usr/bin/xplad keys add validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator2.mnemonics # xpla1pe9mc2q72u94sn2gg52ramrt26x5efw6hr5gt4 -/usr/bin/xplad keys add validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator3.mnemonics +/usr/bin/xplad keys add validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator3.mnemonics # xpla1luqjvjyns9e92h06tq6zqtw76k8xtegfcerzjr -/usr/bin/xplad keys add validator4 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator4.mnemonics +/usr/bin/xplad keys add validator4 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator4.mnemonics # xpla1y6gnay0pv49asun56la09jcmhg2kc949mpftvt -/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user1.mnemonics +/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user1.mnemonics # xpla1u27snswkjpenlscgvszcfjmz8uy2y5qacx0826 -/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user2.mnemonics +/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user2.mnemonics # xpla14xprgqlnuep23kmvsk5utd9pw7w27yeyjlcmcz -- validator5_experimental -/usr/bin/xplad keys add validator5_experimental --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator5_experimental.mnemonics +/usr/bin/xplad keys add validator5_experimental --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator5_experimental.mnemonics # xpla1ur90l8ecppc55gll7k57dk2tvs2w5m9jzptpcj -- volunteer validator1 -/usr/bin/xplad keys add volunteer_validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/volunteer_validator1.mnemonics +/usr/bin/xplad keys add volunteer_validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/volunteer_validator1.mnemonics # xpla1yct6tmmm0twn2wz637lt0yz62xwtqhyqa84uu5 -- volunteer validator2 -/usr/bin/xplad keys add volunteer_validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/volunteer_validator2.mnemonics +/usr/bin/xplad keys add volunteer_validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/volunteer_validator2.mnemonics # xpla1unq7rvf4jkcpmqww09j0u8k37qkgjxm43llwx5 -- volunteer validator3 -/usr/bin/xplad keys add volunteer_validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/volunteer_validator3.mnemonics +/usr/bin/xplad keys add volunteer_validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/volunteer_validator3.mnemonics # 3. Add the genesis accounts /usr/bin/xplad add-genesis-account $(/usr/bin/xplad keys show validator1 -a --keyring-backend test --home $XPLAHOME) 100000000000000000000axpla --keyring-backend test --home $XPLAHOME @@ -49,8 +49,8 @@ rm -f /genesis/* for IDX in 1 2 3 4 do # 1) Copy the credentials - cp /opt/integration_test/validator$IDX/node_key.json $XPLAHOME/config - cp /opt/integration_test/validator$IDX/priv_validator_key.json $XPLAHOME/config + cp /opt/tests/e2e/validator$IDX/node_key.json $XPLAHOME/config + cp /opt/tests/e2e/validator$IDX/priv_validator_key.json $XPLAHOME/config # 2) Execute a gentx /usr/bin/xplad gentx validator$IDX 9000000000000000000axpla \ @@ -104,8 +104,8 @@ cp $XPLAHOME/config/genesis.json /genesis ### followings are for validator setting # 1. Copy the node setting files to the node home dir -cp -r /opt/integration_test/$MONIKER/* $XPLAHOME/config -cp -r /opt/integration_test/common_configs/* $XPLAHOME/config +cp -r /opt/tests/e2e/$MONIKER/* $XPLAHOME/config +cp -r /opt/tests/e2e/common_configs/* $XPLAHOME/config # 2. Get genesis.json from the shared cp /genesis/genesis.json $XPLAHOME/config diff --git a/integration_test/entrypoint_secondary.sh b/tests/e2e/entrypoint_secondary.sh similarity index 68% rename from integration_test/entrypoint_secondary.sh rename to tests/e2e/entrypoint_secondary.sh index 14feb52b..389fc7d8 100644 --- a/integration_test/entrypoint_secondary.sh +++ b/tests/e2e/entrypoint_secondary.sh @@ -1,19 +1,19 @@ #!/bin/sh -# MONIKER=validator1|validator2|validator3|validator4 sh /opt/integration_test/entrypoint.sh +# MONIKER=validator1|validator2|validator3|validator4 sh /opt/tests/e2e/entrypoint.sh # 1. chain init /usr/bin/xplad init $MONIKER --chain-id localtest_1-1 --home $XPLAHOME # 2. copy the node setting files to the node home dir -cp -r /opt/integration_test/$MONIKER/* $XPLAHOME/config -cp -r /opt/integration_test/common_configs/* $XPLAHOME/config +cp -r /opt/tests/e2e/$MONIKER/* $XPLAHOME/config +cp -r /opt/tests/e2e/common_configs/* $XPLAHOME/config sed -i "s/moniker = \"validator1\"/moniker = \"$MONIKER\"/g" $XPLAHOME/config/config.toml # 3. register my validator & users keyfile -/usr/bin/xplad keys add $MONIKER --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/$MONIKER.mnemonics -/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user1.mnemonics -/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user2.mnemonics +/usr/bin/xplad keys add $MONIKER --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/$MONIKER.mnemonics +/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user1.mnemonics +/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user2.mnemonics # 4. get genesis.json from the shared folder # "depends_on" in docker-compose.yml means that it depends on Dockerfile image, not completely wait for the entrypoint exeuction. diff --git a/integration_test/grpcclient_test.go b/tests/e2e/grpcclient_test.go similarity index 99% rename from integration_test/grpcclient_test.go rename to tests/e2e/grpcclient_test.go index 2d88b7bb..07e5b6bb 100644 --- a/integration_test/grpcclient_test.go +++ b/tests/e2e/grpcclient_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/init_test.go b/tests/e2e/init_test.go similarity index 95% rename from integration_test/init_test.go rename to tests/e2e/init_test.go index 0b3f3f1c..fb1121ca 100644 --- a/integration_test/init_test.go +++ b/tests/e2e/init_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "log" diff --git a/integration_test/integration_test.go b/tests/e2e/integration_test.go similarity index 99% rename from integration_test/integration_test.go rename to tests/e2e/integration_test.go index 2cabc720..38aca948 100644 --- a/integration_test/integration_test.go +++ b/tests/e2e/integration_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/misc/token.sol b/tests/e2e/misc/token.sol similarity index 100% rename from integration_test/misc/token.sol rename to tests/e2e/misc/token.sol diff --git a/integration_test/misc/token.sol.abi b/tests/e2e/misc/token.sol.abi similarity index 100% rename from integration_test/misc/token.sol.abi rename to tests/e2e/misc/token.sol.abi diff --git a/integration_test/misc/token.sol.bin b/tests/e2e/misc/token.sol.bin similarity index 100% rename from integration_test/misc/token.sol.bin rename to tests/e2e/misc/token.sol.bin diff --git a/integration_test/misc/token.wasm b/tests/e2e/misc/token.wasm similarity index 100% rename from integration_test/misc/token.wasm rename to tests/e2e/misc/token.wasm diff --git a/integration_test/test_keys/user1.mnemonics b/tests/e2e/test_keys/user1.mnemonics similarity index 100% rename from integration_test/test_keys/user1.mnemonics rename to tests/e2e/test_keys/user1.mnemonics diff --git a/integration_test/test_keys/user2.mnemonics b/tests/e2e/test_keys/user2.mnemonics similarity index 100% rename from integration_test/test_keys/user2.mnemonics rename to tests/e2e/test_keys/user2.mnemonics diff --git a/integration_test/test_keys/validator1.mnemonics b/tests/e2e/test_keys/validator1.mnemonics similarity index 100% rename from integration_test/test_keys/validator1.mnemonics rename to tests/e2e/test_keys/validator1.mnemonics diff --git a/integration_test/test_keys/validator2.mnemonics b/tests/e2e/test_keys/validator2.mnemonics similarity index 100% rename from integration_test/test_keys/validator2.mnemonics rename to tests/e2e/test_keys/validator2.mnemonics diff --git a/integration_test/test_keys/validator3.mnemonics b/tests/e2e/test_keys/validator3.mnemonics similarity index 100% rename from integration_test/test_keys/validator3.mnemonics rename to tests/e2e/test_keys/validator3.mnemonics diff --git a/integration_test/test_keys/validator4.mnemonics b/tests/e2e/test_keys/validator4.mnemonics similarity index 100% rename from integration_test/test_keys/validator4.mnemonics rename to tests/e2e/test_keys/validator4.mnemonics diff --git a/integration_test/test_keys/validator5_experimental.mnemonics b/tests/e2e/test_keys/validator5_experimental.mnemonics similarity index 100% rename from integration_test/test_keys/validator5_experimental.mnemonics rename to tests/e2e/test_keys/validator5_experimental.mnemonics diff --git a/integration_test/test_keys/volunteer_validator1.mnemonics b/tests/e2e/test_keys/volunteer_validator1.mnemonics similarity index 100% rename from integration_test/test_keys/volunteer_validator1.mnemonics rename to tests/e2e/test_keys/volunteer_validator1.mnemonics diff --git a/integration_test/test_keys/volunteer_validator2.mnemonics b/tests/e2e/test_keys/volunteer_validator2.mnemonics similarity index 100% rename from integration_test/test_keys/volunteer_validator2.mnemonics rename to tests/e2e/test_keys/volunteer_validator2.mnemonics diff --git a/integration_test/test_keys/volunteer_validator3.mnemonics b/tests/e2e/test_keys/volunteer_validator3.mnemonics similarity index 100% rename from integration_test/test_keys/volunteer_validator3.mnemonics rename to tests/e2e/test_keys/volunteer_validator3.mnemonics diff --git a/integration_test/token_test.go b/tests/e2e/token_test.go similarity index 99% rename from integration_test/token_test.go rename to tests/e2e/token_test.go index 19f60f7f..e6d71ca5 100644 --- a/integration_test/token_test.go +++ b/tests/e2e/token_test.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package integrationtest +package e2e import ( "errors" diff --git a/integration_test/util_test.go b/tests/e2e/util_test.go similarity index 99% rename from integration_test/util_test.go rename to tests/e2e/util_test.go index ad175903..a562a1e6 100644 --- a/integration_test/util_test.go +++ b/tests/e2e/util_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/validator1/node_key.json b/tests/e2e/validator1/node_key.json similarity index 100% rename from integration_test/validator1/node_key.json rename to tests/e2e/validator1/node_key.json diff --git a/integration_test/validator1/priv_validator_key.json b/tests/e2e/validator1/priv_validator_key.json similarity index 100% rename from integration_test/validator1/priv_validator_key.json rename to tests/e2e/validator1/priv_validator_key.json diff --git a/integration_test/validator2/node_key.json b/tests/e2e/validator2/node_key.json similarity index 100% rename from integration_test/validator2/node_key.json rename to tests/e2e/validator2/node_key.json diff --git a/integration_test/validator2/priv_validator_key.json b/tests/e2e/validator2/priv_validator_key.json similarity index 100% rename from integration_test/validator2/priv_validator_key.json rename to tests/e2e/validator2/priv_validator_key.json diff --git a/integration_test/validator3/node_key.json b/tests/e2e/validator3/node_key.json similarity index 100% rename from integration_test/validator3/node_key.json rename to tests/e2e/validator3/node_key.json diff --git a/integration_test/validator3/priv_validator_key.json b/tests/e2e/validator3/priv_validator_key.json similarity index 100% rename from integration_test/validator3/priv_validator_key.json rename to tests/e2e/validator3/priv_validator_key.json diff --git a/integration_test/validator4/node_key.json b/tests/e2e/validator4/node_key.json similarity index 100% rename from integration_test/validator4/node_key.json rename to tests/e2e/validator4/node_key.json diff --git a/integration_test/validator4/priv_validator_key.json b/tests/e2e/validator4/priv_validator_key.json similarity index 100% rename from integration_test/validator4/priv_validator_key.json rename to tests/e2e/validator4/priv_validator_key.json diff --git a/integration_test/validator5_experimental/node_key.json b/tests/e2e/validator5_experimental/node_key.json similarity index 100% rename from integration_test/validator5_experimental/node_key.json rename to tests/e2e/validator5_experimental/node_key.json diff --git a/integration_test/validator5_experimental/priv_validator_key.json b/tests/e2e/validator5_experimental/priv_validator_key.json similarity index 100% rename from integration_test/validator5_experimental/priv_validator_key.json rename to tests/e2e/validator5_experimental/priv_validator_key.json diff --git a/integration_test/volunteer_validator1/node_key.json b/tests/e2e/volunteer_validator1/node_key.json similarity index 100% rename from integration_test/volunteer_validator1/node_key.json rename to tests/e2e/volunteer_validator1/node_key.json diff --git a/integration_test/volunteer_validator1/priv_validator_key.json b/tests/e2e/volunteer_validator1/priv_validator_key.json similarity index 100% rename from integration_test/volunteer_validator1/priv_validator_key.json rename to tests/e2e/volunteer_validator1/priv_validator_key.json diff --git a/integration_test/volunteer_validator2/node_key.json b/tests/e2e/volunteer_validator2/node_key.json similarity index 100% rename from integration_test/volunteer_validator2/node_key.json rename to tests/e2e/volunteer_validator2/node_key.json diff --git a/integration_test/volunteer_validator2/priv_validator_key.json b/tests/e2e/volunteer_validator2/priv_validator_key.json similarity index 100% rename from integration_test/volunteer_validator2/priv_validator_key.json rename to tests/e2e/volunteer_validator2/priv_validator_key.json diff --git a/integration_test/volunteer_validator3/node_key.json b/tests/e2e/volunteer_validator3/node_key.json similarity index 100% rename from integration_test/volunteer_validator3/node_key.json rename to tests/e2e/volunteer_validator3/node_key.json diff --git a/integration_test/volunteer_validator3/priv_validator_key.json b/tests/e2e/volunteer_validator3/priv_validator_key.json similarity index 100% rename from integration_test/volunteer_validator3/priv_validator_key.json rename to tests/e2e/volunteer_validator3/priv_validator_key.json diff --git a/integration_test/wallet_cosmos_test.go b/tests/e2e/wallet_cosmos_test.go similarity index 99% rename from integration_test/wallet_cosmos_test.go rename to tests/e2e/wallet_cosmos_test.go index a3d5a84b..a7c9df87 100644 --- a/integration_test/wallet_cosmos_test.go +++ b/tests/e2e/wallet_cosmos_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/wallet_evm_test.go b/tests/e2e/wallet_evm_test.go similarity index 99% rename from integration_test/wallet_evm_test.go rename to tests/e2e/wallet_evm_test.go index 14dacb73..2f4f1f3f 100644 --- a/integration_test/wallet_evm_test.go +++ b/tests/e2e/wallet_evm_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/x/reward/abci_test.go b/tests/integration/reward/abci_test.go similarity index 58% rename from x/reward/abci_test.go rename to tests/integration/reward/abci_test.go index 28522558..9b3aa728 100644 --- a/x/reward/abci_test.go +++ b/tests/integration/reward/abci_test.go @@ -10,8 +10,8 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/xpladev/xpla/tests/integration/testutil" "github.com/xpladev/xpla/x/reward" - "github.com/xpladev/xpla/x/reward/keeper" ) // TestBeginBlocker @@ -20,46 +20,46 @@ import ( // 3. 1.1 fee // 4. process 1 block func TestBeginBlocker(t *testing.T) { - input := keeper.CreateTestInput(t) - sh := staking.NewHandler(input.StakingKeeper) + input := testutil.CreateTestInput(t) + sh := staking.NewHandler(input.StakingKeeper.Keeper) sdk.DefaultPowerReduction = sdk.NewIntFromUint64(1000000000000000000) defaultFee := sdk.NewInt(11).Mul(sdk.DefaultPowerReduction).Quo(sdk.NewInt(10)) // 1.1 // create validator & self delegation - for i := 0; i < keeper.ValidatorCount; i++ { - err := input.InitAccountWithCoins(sdk.AccAddress(keeper.Pks[i].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) + for i := 0; i < testutil.ValidatorCount; i++ { + err := input.InitAccountWithCoins(sdk.AccAddress(testutil.Pks[i].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) require.NoError(t, err) - valAddress := sdk.ValAddress(keeper.Pks[i].Address()) - _, err = sh(input.Ctx, keeper.NewTestMsgCreateValidator(valAddress, keeper.Pks[i], input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100))) + valAddress := sdk.ValAddress(testutil.Pks[i].Address()) + _, err = sh(input.Ctx, testutil.NewMsgCreateValidator(valAddress, testutil.Pks[i], input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100))) require.NoError(t, err) } // validator settlement delegation - err := input.InitAccountWithCoins(sdk.AccAddress(keeper.Pks[keeper.ValidatorSettlementIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) + err := input.InitAccountWithCoins(sdk.AccAddress(testutil.Pks[testutil.ValidatorSettlementIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) require.NoError(t, err) - for i := 0; i < keeper.ValidatorCount; i++ { - valAddress := sdk.ValAddress(keeper.Pks[i].Address()) + for i := 0; i < testutil.ValidatorCount; i++ { + valAddress := sdk.ValAddress(testutil.Pks[i].Address()) - _, err = sh(input.Ctx, keeper.NewTestMsgDelegate(sdk.AccAddress(keeper.Pks[keeper.ValidatorSettlementIndex].Address()), valAddress, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 10))) + _, err = sh(input.Ctx, testutil.NewMsgDelegate(sdk.AccAddress(testutil.Pks[testutil.ValidatorSettlementIndex].Address()), valAddress, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 10))) require.NoError(t, err) } - staking.EndBlocker(input.Ctx, input.StakingKeeper) + staking.EndBlocker(input.Ctx, input.StakingKeeper.Keeper) // checkt balance & staking - for i := 0; i < keeper.ValidatorCount; i++ { + for i := 0; i < testutil.ValidatorCount; i++ { require.Equal( t, sdk.NewCoins(sdk.Coin{ Denom: "", Amount: sdk.ZeroInt(), }), - input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(keeper.Pks[i].Address())), + input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(testutil.Pks[i].Address())), ) - valAddress := sdk.ValAddress(keeper.Pks[i].Address()) + valAddress := sdk.ValAddress(testutil.Pks[i].Address()) require.Equal( t, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 110), input.StakingKeeper.Validator(input.Ctx, valAddress).GetBondedTokens(), @@ -71,25 +71,25 @@ func TestBeginBlocker(t *testing.T) { Denom: "", Amount: sdk.ZeroInt(), }), - input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(keeper.Pks[keeper.ValidatorSettlementIndex].Address())), + input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(testutil.Pks[testutil.ValidatorSettlementIndex].Address())), ) // fund fee - err = input.InitAccountWithCoins(sdk.AccAddress(keeper.Pks[keeper.TempIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) + err = input.InitAccountWithCoins(sdk.AccAddress(testutil.Pks[testutil.TempIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) require.NoError(t, err) - err = input.BankKeeper.SendCoinsFromAccountToModule(input.Ctx, sdk.AccAddress(keeper.Pks[keeper.TempIndex].Address()), authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) + err = input.BankKeeper.SendCoinsFromAccountToModule(input.Ctx, sdk.AccAddress(testutil.Pks[testutil.TempIndex].Address()), authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) require.NoError(t, err) // distirubte - input.DistrKeeper.SetPreviousProposerConsAddr(input.Ctx, sdk.ConsAddress(keeper.Pks[0].Address())) + input.DistrKeeper.SetPreviousProposerConsAddr(input.Ctx, sdk.ConsAddress(testutil.Pks[0].Address())) input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 2) voteInfoes := []types.VoteInfo{} - for i := 0; i < keeper.ValidatorCount; i++ { + for i := 0; i < testutil.ValidatorCount; i++ { voteInfoes = append(voteInfoes, types.VoteInfo{ Validator: types.Validator{ - Address: keeper.Pks[i].Address().Bytes(), + Address: testutil.Pks[i].Address().Bytes(), Power: int64(110), }, }) @@ -97,7 +97,7 @@ func TestBeginBlocker(t *testing.T) { distribution.BeginBlocker(input.Ctx, types.RequestBeginBlock{ Header: tmproto.Header{ - ProposerAddress: keeper.Pks[0].Address().Bytes(), + ProposerAddress: testutil.Pks[0].Address().Bytes(), }, LastCommitInfo: types.LastCommitInfo{ Round: int32(1), @@ -129,6 +129,6 @@ func TestBeginBlocker(t *testing.T) { // 3. reserve account (0.0009) require.Equal( t, "900000000000000stake", - input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(keeper.Pks[keeper.ReserveIndex].Address())).String(), + input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(testutil.Pks[testutil.ReserveIndex].Address())).String(), ) } diff --git a/tests/integration/staking/staking_test.go b/tests/integration/staking/staking_test.go new file mode 100644 index 00000000..41c72005 --- /dev/null +++ b/tests/integration/staking/staking_test.go @@ -0,0 +1,53 @@ +package staking_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/xpladev/xpla/tests/integration/testutil" + "github.com/xpladev/xpla/x/staking" +) + +func TestDustShare(t *testing.T) { + input := testutil.CreateTestInput(t) + + sdk.DefaultPowerReduction = sdk.NewInt(1) + for i := 0; i < 2; i++ { + err := input.InitAccountWithCoins(sdk.AccAddress(testutil.Pks[i].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)))) + assert.NoError(t, err) + } + + // 1 validator & 100 self delegation + _, err := input.StakingHandler( + input.Ctx, + testutil.NewMsgCreateValidator( + sdk.ValAddress(testutil.Pks[0].Address()), + testutil.Pks[0], + sdk.NewInt(100))) + assert.NoError(t, err) + + staking.EndBlocker(input.Ctx, input.StakingKeeper) + input.Ctx = input.Ctx.WithBlockHeight(1) + + // slash for dust share + input.SlashingKeeper.Slash(input.Ctx, sdk.ConsAddress(testutil.Pks[0].Address()), sdk.NewDecWithPrec(1, 2), 100, 1) + + // new 1stake delegator + _, err = input.StakingHandler( + input.Ctx, + testutil.NewMsgDelegate(sdk.AccAddress(testutil.Pks[1].Address()), sdk.ValAddress(testutil.Pks[0].Address()), sdk.NewInt(1)), + ) + + assert.NoError(t, err) + + // try to remove all delegation + _, err = input.StakingHandler(input.Ctx, stakingtypes.NewMsgUndelegate(sdk.AccAddress(testutil.Pks[0].Address()), sdk.ValAddress(testutil.Pks[0].Address()), sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(99)))) + assert.NoError(t, err) + + delegations := input.StakingKeeper.GetValidatorDelegations(input.Ctx, sdk.ValAddress(testutil.Pks[0].Address())) + assert.Equal(t, 1, len(delegations)) + assert.Equal(t, sdk.AccAddress(testutil.Pks[1].Address()).String(), delegations[0].DelegatorAddress) +} diff --git a/x/reward/keeper/test_utils.go b/tests/integration/testutil/common.go similarity index 78% rename from x/reward/keeper/test_utils.go rename to tests/integration/testutil/common.go index 92a29a9d..48a80874 100644 --- a/x/reward/keeper/test_utils.go +++ b/tests/integration/testutil/common.go @@ -1,4 +1,4 @@ -package keeper +package testutil import ( "testing" @@ -12,10 +12,8 @@ import ( "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/xpladev/xpla/x/reward/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" simparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" @@ -35,9 +33,16 @@ import ( params "github.com/cosmos/cosmos-sdk/x/params" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + rewardkeeper "github.com/xpladev/xpla/x/reward/keeper" + rewardtypes "github.com/xpladev/xpla/x/reward/types" + stakingkeeper "github.com/xpladev/xpla/x/staking/keeper" + volunteerkeeper "github.com/xpladev/xpla/x/volunteer/keeper" + volunteertypes "github.com/xpladev/xpla/x/volunteer/types" ) const ( @@ -60,6 +65,7 @@ var ModuleBasics = module.NewBasicManager( bank.AppModuleBasic{}, distr.AppModuleBasic{}, staking.AppModuleBasic{}, + slashing.AppModuleBasic{}, mint.AppModuleBasic{}, params.AppModuleBasic{}, ) @@ -76,8 +82,8 @@ func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig { ModuleBasics.RegisterLegacyAminoCodec(amino) ModuleBasics.RegisterInterfaces(interfaceRegistry) - types.RegisterLegacyAminoCodec(amino) - types.RegisterInterfaces(interfaceRegistry) + rewardtypes.RegisterLegacyAminoCodec(amino) + rewardtypes.RegisterInterfaces(interfaceRegistry) return simparams.EncodingConfig{ InterfaceRegistry: interfaceRegistry, Marshaler: marshaler, @@ -88,13 +94,17 @@ func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig { // TestInput nolint type TestInput struct { - Ctx sdk.Context - Cdc *codec.LegacyAmino - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper - RewardKeeper Keeper - StakingKeeper stakingkeeper.Keeper - DistrKeeper distrkeeper.Keeper + Ctx sdk.Context + Cdc *codec.LegacyAmino + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + RewardKeeper rewardkeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + DistrKeeper distrkeeper.Keeper + VolunteerKeeper volunteerkeeper.Keeper + + StakingHandler sdk.Handler } // CreateTestInput nolint @@ -103,10 +113,12 @@ func CreateTestInput(t *testing.T) TestInput { keyBank := sdk.NewKVStoreKey(banktypes.StoreKey) keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey) tKeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) - keyReward := sdk.NewKVStoreKey(types.StoreKey) + keyReward := sdk.NewKVStoreKey(rewardtypes.StoreKey) keyStaking := sdk.NewKVStoreKey(stakingtypes.StoreKey) + keySlahsing := sdk.NewKVStoreKey(slashingtypes.StoreKey) keyDistr := sdk.NewKVStoreKey(distrtypes.StoreKey) keyMint := sdk.NewKVStoreKey(minttypes.StoreKey) + keyVolunteer := sdk.NewKVStoreKey(volunteertypes.StoreKey) db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) @@ -120,8 +132,10 @@ func CreateTestInput(t *testing.T) TestInput { ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyReward, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyStaking, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(keySlahsing, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyDistr, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyMint, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(keyVolunteer, sdk.StoreTypeIAVL, db) require.NoError(t, ms.LoadLatestVersion()) @@ -138,19 +152,21 @@ func CreateTestInput(t *testing.T) TestInput { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, distrtypes.ModuleName: nil, - types.ModuleName: nil, + rewardtypes.ModuleName: nil, } paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, keyParams, tKeyParams) accountKeeper := authkeeper.NewAccountKeeper(appCodec, keyAcc, paramsKeeper.Subspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms) bankKeeper := bankkeeper.NewBaseKeeper(appCodec, keyBank, accountKeeper, paramsKeeper.Subspace(banktypes.ModuleName), blackListAddrs) + var volunteerKeeper volunteerkeeper.Keeper stakingKeeper := stakingkeeper.NewKeeper( appCodec, keyStaking, accountKeeper, bankKeeper, paramsKeeper.Subspace(stakingtypes.ModuleName), + &volunteerKeeper, ) stakingParams := stakingtypes.DefaultParams() @@ -165,20 +181,25 @@ func CreateTestInput(t *testing.T) TestInput { accountKeeper, bankKeeper, stakingKeeper, authtypes.FeeCollectorName, blackListAddrs) + slashingKeeper := slashingkeeper.NewKeeper(appCodec, keySlahsing, &stakingKeeper, paramsKeeper.Subspace(slashingtypes.ModuleName)) + slashingKeeper.SetParams(ctx, slashingtypes.DefaultParams()) + + volunteerKeeper = volunteerkeeper.NewKeeper(keyVolunteer, appCodec, &stakingKeeper, distrKeeper) + distrKeeper.SetFeePool(ctx, distrtypes.InitialFeePool()) distrParams := distrtypes.DefaultParams() distrParams.CommunityTax = sdk.ZeroDec() distrParams.BaseProposerReward = sdk.ZeroDec() distrParams.BonusProposerReward = sdk.ZeroDec() distrKeeper.SetParams(ctx, distrParams) - stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(distrKeeper.Hooks())) + stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(distrKeeper.Hooks(), slashingKeeper.Hooks())) mintKeeper.SetParams(ctx, minttypes.DefaultParams()) feeCollectorAcc := authtypes.NewEmptyModuleAccount(authtypes.FeeCollectorName) notBondedPool := authtypes.NewEmptyModuleAccount(stakingtypes.NotBondedPoolName, authtypes.Burner, authtypes.Staking) bondPool := authtypes.NewEmptyModuleAccount(stakingtypes.BondedPoolName, authtypes.Burner, authtypes.Staking) distrAcc := authtypes.NewEmptyModuleAccount(distrtypes.ModuleName) - rewardAcc := authtypes.NewEmptyModuleAccount(types.ModuleName) + rewardAcc := authtypes.NewEmptyModuleAccount(rewardtypes.ModuleName) accountKeeper.SetModuleAccount(ctx, feeCollectorAcc) accountKeeper.SetModuleAccount(ctx, bondPool) @@ -186,10 +207,10 @@ func CreateTestInput(t *testing.T) TestInput { accountKeeper.SetModuleAccount(ctx, distrAcc) accountKeeper.SetModuleAccount(ctx, rewardAcc) - keeper := NewKeeper( + keeper := rewardkeeper.NewKeeper( appCodec, keyReward, - paramsKeeper.Subspace(types.ModuleName), + paramsKeeper.Subspace(rewardtypes.ModuleName), accountKeeper, bankKeeper, stakingKeeper, @@ -197,7 +218,7 @@ func CreateTestInput(t *testing.T) TestInput { mintKeeper, ) - defaults := types.Params{ + defaults := rewardtypes.Params{ FeePoolRate: sdk.NewDecWithPrec(20, 2), CommunityPoolRate: sdk.NewDecWithPrec(79, 2), ReserveRate: sdk.NewDecWithPrec(1, 2), @@ -206,7 +227,9 @@ func CreateTestInput(t *testing.T) TestInput { } keeper.SetParams(ctx, defaults) - return TestInput{ctx, legacyAmino, accountKeeper, bankKeeper, keeper, stakingKeeper, distrKeeper} + sh := staking.NewHandler(stakingKeeper.Keeper) + + return TestInput{ctx, legacyAmino, accountKeeper, bankKeeper, keeper, stakingKeeper, slashingKeeper, distrKeeper, volunteerKeeper, sh} } func (ti *TestInput) InitAccountWithCoins(addr sdk.AccAddress, coins sdk.Coins) error { @@ -222,22 +245,3 @@ func (ti *TestInput) InitAccountWithCoins(addr sdk.AccAddress, coins sdk.Coins) return nil } - -// NewTestMsgCreateValidator test msg creator -func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { - commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(10, 2), sdk.OneDec(), sdk.OneDec()) - msg, _ := stakingtypes.NewMsgCreateValidator( - address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), - stakingtypes.Description{}, commission, sdk.OneInt(), - ) - - return msg -} - -// NewTestMsgDelegate test msg creator -func NewTestMsgDelegate(delegatorAddress sdk.AccAddress, validatorAddress sdk.ValAddress, amt sdk.Int) *stakingtypes.MsgDelegate { - - return stakingtypes.NewMsgDelegate( - delegatorAddress, validatorAddress, sdk.NewCoin(sdk.DefaultBondDenom, amt), - ) -} diff --git a/tests/integration/testutil/staking.go b/tests/integration/testutil/staking.go new file mode 100644 index 00000000..c6801303 --- /dev/null +++ b/tests/integration/testutil/staking.go @@ -0,0 +1,27 @@ +package testutil + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// NewMsgCreateValidator test msg creator +func NewMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(10, 2), sdk.OneDec(), sdk.OneDec()) + msg, _ := stakingtypes.NewMsgCreateValidator( + address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), + stakingtypes.Description{}, commission, sdk.OneInt(), + ) + + return msg +} + +// NewMsgDelegate test msg creator +func NewMsgDelegate(delegatorAddress sdk.AccAddress, validatorAddress sdk.ValAddress, amt sdk.Int) *stakingtypes.MsgDelegate { + + return stakingtypes.NewMsgDelegate( + delegatorAddress, validatorAddress, sdk.NewCoin(sdk.DefaultBondDenom, amt), + ) +}