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

Activate EVM test #54

Merged
merged 8 commits into from
Dec 12, 2022
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
26 changes: 26 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Effects

- [ ] Soft update
- [ ] Breaking change
- [ ] Chain fork related

<!-- If internal PR & if it is needed to check from a specific person, please mention. Or you may delete it -->
## Major Reviewer

<!-- List them -->

## Background
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## Summary
<!--- Provide a summary of your changes. -->
<!--- It's a good idea to include the issue you are trying to solve and how to fix it. -->

<!--- Add More if you need. -->

## Checklist

- [ ] Backward compatible?
- [ ] Test enough in your local environment?
- [ ] Add related test cases?
37 changes: 37 additions & 0 deletions .github/release-drafter-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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
32 changes: 32 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Go

on:
push:
branches: [ "main", "cube", "hypercube", "tesseract", "release/*" ]
pull_request:
branches: [ "*" ]

jobs:

build:
runs-on: ubuntu-latest

strategy:
matrix:
go-version: [1.18.x, 1.19.x]

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Protogen test
run: make proto-gen

- name: Test
run: |
go mod tidy
make test
33 changes: 33 additions & 0 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Integration test

on:
push:
branches: [ "main", "cube", "hypercube", "tesseract", "release/*" ]
pull_request:
branches: [ "*" ]

jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup network
run: |
mkdir ~/genesis
cd integration_test && docker-compose up -d
docker ps
sleep 10

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x

- name: Integration test
run: cd integration_test && go test

- name: Teardown
run: cd integration_test && docker-compose down
13 changes: 13 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release Drafter
on:
push:
branches: [ "main", "cube", "hypercube", "tesseract" ]

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5

with:
config-name: release-drafter-config.yml
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# xpla localnet
#
# build:
# docker build --force-rm -t xpladev/xpla .
# run:
# docker run --rm -it --env-file=path/to/.env --name xpla-localnet xpladev/xpla

### BUILD
FROM golang:1.18-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.0.0

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 7d2239e9f25e96d0d4daba982ce92367aacf0cbd95d2facb8442268f2b1cc1fc
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479

# 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

# Build executable
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS='-linkmode=external -extldflags "-L/localnet/mimalloc/build -lmimalloc -Wl,-z,muldefs -static"' make build

# --------------------------------------------------------
FROM alpine:3.15 AS runtime

WORKDIR /opt
RUN [ "mkdir", "-p", "/opt/integration_test" ]

COPY --from=build /localnet/build/xplad /usr/bin/xplad
COPY --from=build /localnet/integration_test /opt/integration_test

# Expose Cosmos ports
EXPOSE 9090
EXPOSE 8545
EXPOSE 26656
#EXPOSE 26657

# Set entry point
CMD [ "/usr/bin/xplad", "version" ]
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ all: install
install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/xplad

build: go.sum
go build -mod=readonly $(BUILD_FLAGS) -o build/xplad ./cmd/xplad

.PHONY: test
test: go.sum
go test -short ./...

go.sum: go.mod
@go mod verify
@go mod tidy
Expand Down
8 changes: 5 additions & 3 deletions ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ante_test

import (
"fmt"
"math/rand"
"testing"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -13,7 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/stretchr/testify/suite"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

xplaapp "github.com/xpladev/xpla/app"
Expand All @@ -35,9 +35,11 @@ func TestIntegrationTestSuite(t *testing.T) {
}

func (s *IntegrationTestSuite) SetupTest() {
app := xplahelpers.Setup(s.T(), false, 1)
chainId := fmt.Sprintf("test_%d-%d", rand.Intn(1000), rand.Intn(10))

app := xplahelpers.Setup(s.T(), chainId, false, 1)
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
ChainID: chainId,
Height: 1,
})

Expand Down
3 changes: 2 additions & 1 deletion app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type EmptyAppOptions struct{}

func (EmptyAppOptions) Get(o string) interface{} { return nil }

func Setup(t *testing.T, isCheckTx bool, invCheckPeriod uint) *xplaapp.XplaApp {
func Setup(t *testing.T, chainId string, isCheckTx bool, invCheckPeriod uint) *xplaapp.XplaApp {
t.Helper()

app, genesisState := setup(!isCheckTx, invCheckPeriod)
Expand All @@ -55,6 +55,7 @@ func Setup(t *testing.T, isCheckTx bool, invCheckPeriod uint) *xplaapp.XplaApp {
// Initialize the chain
app.InitChain(
abci.RequestInitChain{
ChainId: chainId,
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.0
Expand Down Expand Up @@ -120,7 +121,6 @@ require (
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions integration_test/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# only for integration test purpose!
XPLAHOME=/opt/.xpla
48 changes: 48 additions & 0 deletions integration_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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
Loading