Skip to content

Commit

Permalink
test: re-enable acceptance test, with kgw
Browse files Browse the repository at this point in the history
This add kgw test support, also re-enable acceptance test in ci.
  • Loading branch information
Yaiba authored Feb 27, 2025
1 parent 3f95602 commit 3de44f8
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 70 deletions.
19 changes: 0 additions & 19 deletions .github/filters-old.yaml

This file was deleted.

43 changes: 18 additions & 25 deletions .github/workflows/ci-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,22 @@ jobs:
task build:cli
task build:kwild
# - name: compile the core/client/example app
# run: go build -o /dev/null
# working-directory: core/client/example

# - name: compile the core/gatewayclient/example app
# run: go build -o /dev/null
# working-directory: core/gatewayclient/example
# - name: compile the core/client/example app
# run: go build -o /dev/null
# working-directory: core/client/example
#
# - name: compile the core/gatewayclient/example app
# run: go build -o /dev/null
# working-directory: core/gatewayclient/example

- name: Generate go vendor
if: false
run: |
task vendor
- name: Set up Docker Buildx
if: false
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers for kwild # both restore and save
if: false
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache-kwild
Expand All @@ -148,7 +145,6 @@ jobs:
${{ runner.os }}-buildx-kwild
- name: Build kwild image
if: false
id: docker_build_kwild
uses: docker/build-push-action@v6
with:
Expand All @@ -166,13 +162,11 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache-kwild
cache-to: type=local,dest=/tmp/.buildx-cache-kwild-new

# - name: Run acceptance test
# run: |
# testUserID=$(id -u)
# testGroupID=$(id -g)
# cp test/acceptance/docker-compose.override.yml.example test/acceptance/docker-compose.override.yml
# sed -i "s/\${UID}:\${GID}/${testUserID}:${testGroupID}/g" test/acceptance/docker-compose.override.yml
# KACT_LOG_LEVEL=warn task test:act:nb
- name: Run acceptance test
run: |
testUserID=$(id -u)
testGroupID=$(id -g)
KACT_LOG_LEVEL=warn task test:act:nb -- -ugid "$testUserID:$testGroupID"
# - name: Run integration test
# run: |
Expand All @@ -185,15 +179,14 @@ jobs:
# KIT_LOG_LEVEL=warn task test:it:nb

- name: Move cache
if: false
run: |
rm -rf /tmp/.buildx-cache-kwild
mv /tmp/.buildx-cache-kwild-new /tmp/.buildx-cache-kwild
# - name: Prune Docker
# if: ${{ always() }}
# run: docker rm $(docker ps -a -q) -f ; docker network prune -f ; docker volume prune -f || true
- name: Prune Docker
if: ${{ always() }}
run: docker rm $(docker ps -a -q) -f ; docker network prune -f ; docker volume prune -f || true

# - name: Show error log
# if: ${{ failure() }}
# run: grep -C 20 -s -i -r -e 'kwild version' -e 'error' -e 'warn' /tmp/TestKwilAct*/*.log /tmp/TestKwilInt*/*.log /tmp/TestKwilInt*/*/*.log
- name: Show error log
if: ${{ failure() }}
run: grep -C 20 -s -i -r -e 'kwild version' -e 'error' -e 'warn' /tmp/TestKwilAct*/*.log /tmp/TestKwilInt*/*.log /tmp/TestKwilInt*/*/*.log
18 changes: 8 additions & 10 deletions .github/workflows/kgw-test-reuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ jobs:
# vendor is used to bypass private repo issues;
# if kgw on non-release branches, we want to use go workspace, so that kgw
# always uses the latest version of kwil-db/core
# when build in workspace, the dockerfile requires kgw and kwild in same folder.
run: |
echo "KWK_DIR=$(pwd)/.." >> $GITHUB_ENV
kdbDir=$(pwd)
echo "KDB_DIR=$(pwd)" >> $GITHUB_ENV
echo "current dir: " $kdbDir
Expand All @@ -129,10 +129,11 @@ jobs:
fi
cd -
cd $kdbDir
echo "current dir: " $pwd
- name: Build kgw image
id: docker_build_kgw
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: ${{ env.KGW_DIR }}/..
load: true
Expand Down Expand Up @@ -163,7 +164,7 @@ jobs:
- name: Build kwild image
id: docker_build_kwild
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
load: true
Expand All @@ -172,7 +173,7 @@ jobs:
git_commit=${{ github.sha }}
version=${{ env.GIT_TAG }}
build_time=${{ env.BUILD_TIME }}
file: ./build/package/docker/kwild.dockerfile
file: ./contrib/docker/kwild.dockerfile
push: false
tags: kwild:latest
cache-from: type=local,src=/tmp/.buildx-cache-kwild
Expand All @@ -182,17 +183,15 @@ jobs:
run: |
task build:cli
- name: Run kgw integration test
- name: Run kgw acceptance test
run: |
testUserID=$(id -u)
testGroupID=$(id -g)
cp test/integration/docker-compose.override.yml.example test/integration/docker-compose.override.yml
sed -i "s/\${UID}:\${GID}/${testUserID}:${testGroupID}/g" test/integration/docker-compose.override.yml
KIT_LOG_LEVEL=warn go test -count=1 -timeout 0 ./test/integration -run ^TestKGW$ -v
KACT_LOG_LEVEL=warn task test:act:nb -- -kgw -ugid "$testUserID:$testGroupID"
- name: Run kwil-js test against kwild & kgw
run: |
cd deployments/compose/kwil
cd contrib/docker/compose/kwil
echo "run kwild in docker"
docker compose up -d
# clone kwil-js
Expand All @@ -214,7 +213,6 @@ jobs:
-b "http://kwild:8484" \
--chain-id $chain_id \
--allow-adhoc-query \
--allow-deploy-db \
--log-level debug
echo "run KWIL-JS TEST against kwild(http://localhost:8484), with $chain_id"
PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000001 CHAIN_ID=$chain_id GATEWAY_ON=false GAS_ON=false KWIL_PROVIDER=http://localhost:8484 npm run integration
Expand Down
68 changes: 54 additions & 14 deletions test/acceptance/act_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
)

// TODO:
// - kgw tests
// - log / "notice()" tests

var dev = flag.Bool("dev", false, "run for development purpose (no tests)")
var withKGW = flag.Bool("kgw", false, "test with kgw")

func TestLocalDevSetup(t *testing.T) {
if !*dev {
Expand All @@ -44,7 +44,7 @@ func TestLocalDevSetup(t *testing.T) {
cancel()
}()

client := setupSingleNodeClient(t, ctx, setup.Go, false)
client := setupSingleNodeClient(t, ctx, setup.Go, *withKGW)
ci, err := client.ChainInfo(ctx)
if err != nil {
t.Fatal(err)
Expand All @@ -69,30 +69,56 @@ var (
}
return privk
}()

kgwSvc = &setup.CustomService{
ServiceName: "kgw",
DockerImage: "kgw:latest",
Command: `--log-level debug --log-outputs stdout /app/kgw.log --cors-allow-origins * --backends node0:8484 node1:8484 --domain http://localhost:8090 --statement 'Trust me ok?' --session-secret 'kgwtest' --chain-id kwil-testnet --allow-adhoc-query --devmode`,
ExposedPort: "8090",
InternalPort: "8090",
ServiceProto: "http",
WaitMsg: "KGW Server started",
DependsOn: "node0",
}
)

// setupSingleNodeClient creates a single node network for testing,
// and returns the client
func setupSingleNodeClient(t *testing.T, ctx context.Context, d setup.ClientDriver, usingKGW bool) setup.JSONRPCClient {
// setupSingleNodeClient creates a single node network for testing, and returns the client.
// If useKGW=true, a KGW node will be created, the returned client will talk to KGW instead of the kwild node.
func setupSingleNodeClient(t *testing.T, ctx context.Context, d setup.ClientDriver, useKGW bool) setup.JSONRPCClient {
t.Helper()

signer := auth.GetUserSigner(UserPrivkey1)
ident, err := auth.EthSecp256k1Authenticator{}.Identifier(signer.CompactID())
require.NoError(t, err)

var extraServices []*setup.CustomService

if useKGW {
extraServices = append(extraServices, kgwSvc)
}

testnet := setup.SetupTests(t, &setup.TestConfig{
ClientDriver: d,
Network: &setup.NetworkConfig{
DBOwner: ident,
Nodes: []*setup.NodeConfig{
setup.DefaultNodeConfig(),
},
ExtraServices: extraServices,
},
})
return testnet.Nodes[0].JSONRPCClient(t, ctx, &setup.ClientOptions{
UsingKGW: usingKGW,

opts := &setup.ClientOptions{
PrivateKey: UserPrivkey1,
})
}

kgwNode, ok := testnet.SearchExtraNode("kgw")
if ok {
opts.UsingKGW = true
opts.Endpoint = kgwNode.ExposedChainRPC
}

return testnet.Nodes[0].JSONRPCClient(t, ctx, opts)
}

func Test_Transfer(t *testing.T) {
Expand All @@ -118,6 +144,11 @@ func Test_Transfer(t *testing.T) {
return val
}

var extraServices []*setup.CustomService
if *withKGW {
extraServices = append(extraServices, kgwSvc)
}

testnet := setup.SetupTests(t, &setup.TestConfig{
ClientDriver: driver,
Network: &setup.NetworkConfig{
Expand All @@ -134,14 +165,23 @@ func Test_Transfer(t *testing.T) {
Nodes: []*setup.NodeConfig{
setup.DefaultNodeConfig(),
},
DBOwner: stringAddress(userPrivateKey),
DBOwner: stringAddress(userPrivateKey),
ExtraServices: extraServices,
},
})

// user 1 will send funds to user 2. User 2 will check that they received the funds
user1 := testnet.Nodes[0].JSONRPCClient(t, ctx, &setup.ClientOptions{
cltOpts := &setup.ClientOptions{
PrivateKey: userPrivateKey,
})
}

kgwNode, ok := testnet.SearchExtraNode("kgw")
if ok {
cltOpts.UsingKGW = true
cltOpts.Endpoint = kgwNode.ExposedChainRPC
}

// user 1 will send funds to user 2. User 2 will check that they received the funds
user1 := testnet.Nodes[0].JSONRPCClient(t, ctx, cltOpts)

// user 1 creates an action, which user 2 will call to test they have funds
tx, err := user1.ExecuteSQL(ctx, "CREATE ACTION do_something() public {}", nil, opts)
Expand Down Expand Up @@ -178,7 +218,7 @@ func Test_Engine(t *testing.T) {
for _, driver := range setup.AllDrivers {
t.Run("engine_"+driver.String(), func(t *testing.T) {
ctx := context.Background()
client := setupSingleNodeClient(t, ctx, driver, false)
client := setupSingleNodeClient(t, ctx, driver, *withKGW)

// deploy the schema
tx, err := client.ExecuteSQL(ctx, usersSchema, nil, opts)
Expand Down Expand Up @@ -237,7 +277,7 @@ func Test_Roundtrip(t *testing.T) {
for _, driver := range setup.AllDrivers {
t.Run("roundtrip_"+driver.String(), func(t *testing.T) {
ctx := context.Background()
client := setupSingleNodeClient(t, ctx, driver, false)
client := setupSingleNodeClient(t, ctx, driver, *withKGW)

// a table that stores all data types
tx, err := client.ExecuteSQL(ctx, `
Expand Down
7 changes: 7 additions & 0 deletions test/setup/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func generateCompose(dockerNetwork string, testnetDir string, nodeConfs []*NodeC
Command: svc.Command,
ExposedPort: svc.ExposedPort,
InternalPort: svc.InternalPort,
DependsOn: svc.DependsOn,
}

if userAndGroupIDs != nil {
svcTmpl.UserID = userAndGroupIDs[0]
svcTmpl.GroupID = userAndGroupIDs[1]
Expand Down Expand Up @@ -180,6 +182,7 @@ type serviceTemplate struct {
// InternalPort is the port that the service is running on internally.
// It must be set if ExposedPort is set
InternalPort string
DependsOn string
}

func (s *serviceTemplate) generate(r *bytes.Buffer) error {
Expand All @@ -200,6 +203,10 @@ type CustomService struct {
// OPTIONAL: InternalPort is the port that the service is running on internally.
// It must be set if ExposedPort is set
InternalPort string
// OPTIONAL: ServiceProto is the proto that the service use.
ServiceProto string
// OPTIONAL: WaitMsg is a log that Docker will wait for before considering the service to be up
WaitMsg string
// OPTIONAL: DependsOn specify a service that needs to be healthy
DependsOn string
}
2 changes: 2 additions & 0 deletions test/setup/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type ClientOptions struct {
PrivateKey crypto.PrivateKey
// UsingKGW specifies whether to use the gateway client.
UsingKGW bool
// Endpoint specifies the endpoint to use. This is mostly for kgw.
Endpoint string
// ChainID is the chain ID to use.
ChainID string
}
Expand Down
2 changes: 2 additions & 0 deletions test/setup/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
const (
jsonRPCPort = 8484
p2pPort = 6600

kgwRPCPort = 8090
)

// EnsureNetworkExist creates a new docker network with a random UUID name.
Expand Down
Loading

0 comments on commit 3de44f8

Please sign in to comment.