Skip to content

Commit

Permalink
test kgw temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba committed Jan 8, 2024
1 parent 78b2aca commit e4373a9
Show file tree
Hide file tree
Showing 27 changed files with 474 additions and 289 deletions.
46 changes: 40 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:

jobs:
unit-test:
runs-on: ubuntu-latest
#runs-on: ubuntu-latest
runs-on: self-hosted
if: ${{ !github.event.pull_request.draft }} # only run on non-draft PRs
steps:
- name: Checkout
Expand All @@ -26,9 +27,6 @@ jobs:
version: '23.4'
repo-token: ${{ secrets.KWIL_MACH_SECRET }}

# - name: Install swagger-codegen
# uses: swagger-api/swagger-codegen/.github/actions/generate/action.yml@main

- name: Install Taskfile
uses: arduino/setup-task@v1
with:
Expand Down Expand Up @@ -77,8 +75,9 @@ jobs:
run: |
task test:unit
acceptance-test:
runs-on: ubuntu-latest
integration-test:
#runs-on: ubuntu-latest
runs-on: self-hosted
if: ${{ !github.event.pull_request.draft }} # only run on non-draft PRs
steps:
- name: Checkout
Expand Down Expand Up @@ -150,6 +149,30 @@ jobs:
run: |
docker pull kwilbrennan/extensions-math:multi-arch --platform linux/amd64
- name: pull kgw repo & create vendor
# we only pull the repo, not build the image, because we want to use the cache
# provided by the docker/build-push-action
# vendor is used to bypass private repo issues
run: |
rm -rf /tmp/kgw
git clone https://github.com/kwilteam/kgw.git /tmp/kgw
cd /tmp/kgw
go mod vendor
cd -
- name: Build kgw image
id: docker_build_kgw
uses: docker/build-push-action@v4
with:
context: /tmp/kgw
load: true
builder: ${{ steps.buildx.outputs.name }}
file: /tmp/kgw/Dockerfile
push: false
tags: kgw:latest
cache-from: type=local,src=/tmp/.buildx-cache-kgw
cache-to: type=local,dest=/tmp/.buildx-cache-kgw-new

- name: Build kwild image
id: docker_build_kwild
uses: docker/build-push-action@v4
Expand All @@ -167,6 +190,7 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache-kwild
cache-to: type=local,dest=/tmp/.buildx-cache-kwild-new

# maybe no need?
- name: Run acceptance test
run: |
echo "UID=$(id -u)" >> test/acceptance/.env
Expand All @@ -175,7 +199,17 @@ jobs:
echo "KACT_DOCKER_COMPOSE_OVERRIDE_FILE=docker-compose.override.yml" >> test/acceptance/.env
task test:act:nb
- name: Run integration test
run: |
echo "UID=$(id -u)" >> test/integration/.env
echo "GID=$(id -g)" >> test/integration/.env
cp test/integration/docker-compose.override.yml.example test/integration/docker-compose.override.yml
echo "KIT_DOCKER_COMPOSE_OVERRIDE_FILE=docker-compose.override.yml" >> test/integration/.env
task test:it:nb:all
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache-kwild
mv /tmp/.buildx-cache-kwild-new /tmp/.buildx-cache-kwild
rm -rf /tmp/.buildx-cache-kgw
mv /tmp/.buildx-cache-kgw-new /tmp/.buildx-cache-kgw
125 changes: 0 additions & 125 deletions .github/workflows/on-main.yml

This file was deleted.

10 changes: 8 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ tasks:
desc: Start the dev environment(with testnet) without rebuilding docker image
dir: test # different module
cmds:
- go test ./integration -timeout 12h -dev -v
- go test ./integration -run ^TestLocalDevSetup$ -timeout 12h -dev -v

# ************ test ************
# test with build:docker task support passing CLI_ARGS to go test, e.g. task test:act -- -debug
Expand Down Expand Up @@ -216,7 +216,7 @@ tasks:
- go test ./... -tags=ext_test -count=1 -race

test:it:
desc: Run integration tests
desc: Run integration tests ('short' mode)
deps:
- task: build:cli
- task: build:admin
Expand All @@ -225,6 +225,12 @@ tasks:
- task: test:it:nb

test:it:nb:
desc: Run integration tests ('short' mode)
dir: test # different module
cmds:
- go test -short -count=1 -timeout 0 ./integration -v {{.CLI_ARGS}}

test:it:nb:all:
desc: Run integration tests
dir: test # different module
cmds:
Expand Down
17 changes: 11 additions & 6 deletions core/rpc/client/user/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ func (c *Client) Broadcast(ctx context.Context, tx *transactions.Transaction, sy
// ErrInsufficientBalance, ErrWrongChain, etc. but how? the response
// body had better have retained the response error details!
if res != nil {
// fmt.Println("broadcast", res.StatusCode, res.Status)
if swaggerErr, ok := err.(httpTx.GenericSwaggerError); ok {
body := swaggerErr.Body() // fmt.Println(string(body))
return nil, parseBroadcastError(body)
if ok, _err := parseBroadcastError(body); ok {
return nil, _err
} else {
return nil, err // return the original error(unparsed)
}
}
}

return nil, err
}
defer res.Body.Close()
Expand Down Expand Up @@ -265,12 +269,14 @@ func (c *Client) Query(ctx context.Context, dbid string, query string) ([]map[st
return unmarshalMapResults(decodedResult)
}

func parseBroadcastError(respTxt []byte) error {
// parseBroadcastError parses the response body from a broadcast error.
// It returns true if the error was parsed successfully, false otherwise.
func parseBroadcastError(respTxt []byte) (bool, error) {
var protoStatus status.Status
err := protojson.Unmarshal(respTxt, &protoStatus) // jsonpb is deprecated, otherwise we could use the resp.Body directly
if err != nil {
if err = json.Unmarshal(respTxt, &protoStatus); err != nil {
return err
return false, err
}
}
stat := grpcStatus.FromProto(&protoStatus)
Expand Down Expand Up @@ -308,8 +314,7 @@ func parseBroadcastError(respTxt []byte) error {
}
}

return err

return true, err
}

func parseErrorResponse(respTxt []byte) error {
Expand Down
5 changes: 3 additions & 2 deletions internal/abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ func (a *AbciApp) CheckTx(ctx context.Context, incoming *abciTypes.RequestCheckT
// Verify the correct chain ID is set, if it is set.
if protected := tx.Body.ChainID != ""; protected && tx.Body.ChainID != a.cfg.ChainID {
code = codeWrongChain
logger.Info("wrong chain ID", zap.String("payloadType", tx.Body.PayloadType.String()))
logger.Info("wrong chain ID",
zap.String("payloadType", tx.Body.PayloadType.String()))
return &abciTypes.ResponseCheckTx{Code: code.Uint32(), Log: "wrong chain ID"}, nil
}
// Verify Payload type
Expand Down Expand Up @@ -263,7 +264,7 @@ func (a *AbciApp) executeTx(ctx context.Context, rawTx []byte, logger *log.Logge
Code: code.Uint32(),
GasUsed: gasUsed,
Events: events,
Log: "success",
Log: "",
// Data, GasWanted, Info, Codespace
}

Expand Down
1 change: 1 addition & 0 deletions internal/services/grpc/txsvc/v1/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func (s *Service) Call(ctx context.Context, req *txpb.CallRequest) (*txpb.CallResponse, error) {
body, msg, err := convertActionCall(req)
if err != nil {
// NOTE: http api needs to be able to get the error message
return nil, status.Errorf(codes.InvalidArgument, "failed to convert action call: %s", err.Error())
}

Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- "26657:26657"
- "40000:40000" # debugger
env_file:
- .env # docker compose by default will use this file, here just make it explicit
- .env # docker compose by default will use this file if presented, here just make it explicit
volumes:
- type: bind
source: ${KWIL_HOME:-./.testnode}
Expand All @@ -26,7 +26,7 @@ services:
--root-dir=/app/kwil
--log.level=${LOG_LEVEL:-info}
--app.extension-endpoints=ext:50051
--app.admin-listen-addr=unix:///var/run/kwil/admin.sock
--app.admin-listen-addr=unix:///tmp/admin.sock
--app.grpc-listen-addr=:50051
--app.http-listen-addr=:8080
--chain.p2p.external-address=tcp://0.0.0.0:26656
Expand Down
16 changes: 8 additions & 8 deletions test/acceptance/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ const TestChainID = "kwil-test-chain"

// ActTestCfg is the config for acceptance test
type ActTestCfg struct {
HTTPEndpoint string
GrpcEndpoint string
P2PAddress string // cometbft p2p address
AdminClientUnixSocket string
HTTPEndpoint string
GrpcEndpoint string
P2PAddress string // cometbft p2p address
AdminRPC string // tcp or unix socket

SchemaFile string
DockerComposeFile string
Expand Down Expand Up @@ -136,7 +136,7 @@ func (r *ActHelper) LoadConfig() *ActTestCfg {
HTTPEndpoint: getEnv("KACT_HTTP_ENDPOINT", "http://localhost:8080"),
GrpcEndpoint: getEnv("KACT_GRPC_ENDPOINT", "localhost:50051"),
P2PAddress: getEnv("KACT_CHAIN_ENDPOINT", "tcp://0.0.0.0:26656"),
AdminClientUnixSocket: getEnv("KACT_ADMIN_CLIENT_UNIX_SOCKET", "tcp://localhost:50151"),
AdminRPC: getEnv("KACT_ADMIN_RPC", "unix:///tmp/admin.sock"),
DockerComposeFile: getEnv("KACT_DOCKER_COMPOSE_FILE", "./docker-compose.yml"),
DockerComposeOverrideFile: getEnv("KACT_DOCKER_COMPOSE_OVERRIDE_FILE", "./docker-compose.override.yml"),
}
Expand Down Expand Up @@ -323,7 +323,7 @@ func (r *ActHelper) getHTTPClientDriver(signer auth.Signer) KwilAcceptanceDriver
})
require.NoError(r.t, err, "failed to create http client")

return driver.NewKwildClientDriver(kwilClt, logger)
return driver.NewKwildClientDriver(kwilClt, signer, logger)
}

func (r *ActHelper) getGRPCClientDriver(signer auth.Signer) KwilAcceptanceDriver {
Expand All @@ -340,7 +340,7 @@ func (r *ActHelper) getGRPCClientDriver(signer auth.Signer) KwilAcceptanceDriver
})
require.NoError(r.t, err, "failed to create grpc client")

return driver.NewKwildClientDriver(kwilClt, logger)
return driver.NewKwildClientDriver(kwilClt, signer, logger)
}

func (r *ActHelper) getCliDriver(privKey string, identifier []byte) KwilAcceptanceDriver {
Expand All @@ -350,5 +350,5 @@ func (r *ActHelper) getCliDriver(privKey string, identifier []byte) KwilAcceptan
cliBinPath := path.Join(path.Dir(currentFilePath),
fmt.Sprintf("../../.build/kwil-cli-%s-%s", runtime.GOOS, runtime.GOARCH))

return driver.NewKwilCliDriver(cliBinPath, r.cfg.HTTPEndpoint, privKey, TestChainID, identifier, logger)
return driver.NewKwilCliDriver(cliBinPath, r.cfg.HTTPEndpoint, privKey, TestChainID, identifier, false, logger)
}
2 changes: 1 addition & 1 deletion test/acceptance/kwild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var dev = flag.Bool("dev", false, "run for development purpose (no tests)")
var remote = flag.Bool("remote", false, "test against remote node")
var noCleanup = flag.Bool("messy", false, "do not cleanup test directories or stop the docker compose when done")

var drivers = flag.String("drivers", "grpc,cli", "comma separated list of drivers to run")
var drivers = flag.String("drivers", "http,cli", "comma separated list of drivers to run")

func TestKwildTransferAcceptance(t *testing.T) {
if testing.Short() {
Expand Down
Loading

0 comments on commit e4373a9

Please sign in to comment.