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

DO NOT MERGE test: re-enable acceptance test, with kgw #1418

Closed
wants to merge 8 commits into from
Closed
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
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
7 changes: 2 additions & 5 deletions .github/workflows/kgw-test-reuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,11 @@ 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: |
Expand All @@ -214,7 +212,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
Loading