Skip to content

Commit

Permalink
test: Add test build tags (#460)
Browse files Browse the repository at this point in the history
* test: Tag integration tests

* test: Tag unit tests

* test: Move rate limit test alongside solver

* test: Move integration test to main_test package

* docs: Update testing instructions

* test: Update stack test commands

Adds a command for Go unit tests.

* test: Skip broken tests

We have an issue for them at #385.

* test: Update tests with separate Go and Hardhat unit tests
  • Loading branch information
bgins authored and walkah committed Dec 10, 2024
1 parent ccea6de commit bf71101
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- name: Run unit tests
run: ./stack unit-tests

- name: Run hardhat unit tests
run: ./stack unit-tests-hardhat

run-integration-tests:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 3 additions & 1 deletion LOCAL_DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ Once all the services are up and running this command can be used to trigger an

### Tests

There are two commands that can be used to run existing tests: `./stack unit-tests` and `./stack integration-tests` (bear in mind the latter expects a blockchain node to be running locally).
Run the Go unit tests with `./stack unit-tests` and the Hardhat unit tests with `./stack unit-tests-hardhat`.

Run the integration tests with `./stack integration-tests`. The integration tests expect all parts of the stack are running, except the request to run a job. See [Using Docker Compose](./LOCAL_DEVELOPMENT.md#using-docker-compose) to run the stack.

## Notes on tooling

Expand Down
2 changes: 2 additions & 0 deletions pkg/module/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package module

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/resourceprovider/cpuworker_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package resourceprovider

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/solver/matcher/matcher_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package matcher

import (
Expand Down
4 changes: 3 additions & 1 deletion test/ratelimit_test.go → pkg/solver/ratelimit_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package main
//go:build integration

package solver_test

import (
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions pkg/system/otel_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package system

import "testing"
Expand Down
15 changes: 13 additions & 2 deletions pkg/web3/sdk_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
//go:build unit

package web3_test

import (
"context"
"crypto/ecdsa"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"golang.org/x/crypto/sha3"
"log"
"math/big"
"os"
"testing"

"github.com/ethereum/go-ethereum/crypto"
"golang.org/x/crypto/sha3"

"github.com/BurntSushi/toml"
"github.com/lilypad-tech/lilypad/pkg/options"
"github.com/lilypad-tech/lilypad/pkg/system"
Expand Down Expand Up @@ -65,6 +68,8 @@ func CreateTestWeb3SDK() (*web3.Web3SDK, error) {
}

func TestGetBalance(t *testing.T) {
t.Skip("Issue: https://github.com/Lilypad-Tech/lilypad/issues/385")

sdk, err := CreateTestWeb3SDK()
if err != nil {
t.Fatalf("Failed to create Web3SDK: %v", err)
Expand All @@ -78,6 +83,8 @@ func TestGetBalance(t *testing.T) {
}

func TestGetLPBalance(t *testing.T) {
t.Skip("Issue: https://github.com/Lilypad-Tech/lilypad/issues/385")

sdk, err := CreateTestWeb3SDK()
if err != nil {
t.Fatalf("Failed to create Web3SDK: %v", err)
Expand All @@ -90,6 +97,8 @@ func TestGetLPBalance(t *testing.T) {
}

func TestGetLPBalanceNoBalance(t *testing.T) {
t.Skip("Issue: https://github.com/Lilypad-Tech/lilypad/issues/385")

sdk, err := CreateTestWeb3SDK()
noBalanceInt := big.NewInt(0)
if err != nil {
Expand All @@ -114,6 +123,8 @@ func TestGetLPBalanceNoBalance(t *testing.T) {
}

func TestGetBlockNumber(t *testing.T) {
t.Skip("Issue: https://github.com/Lilypad-Tech/lilypad/issues/385")

sdk, err := CreateTestWeb3SDK()
if err != nil {
t.Fatalf("Failed to create Web3SDK: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/web3/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package web3

import (
Expand Down
7 changes: 5 additions & 2 deletions stack
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ function mediator() {
############################################################################

function unit-tests() {
go test -v -tags="unit" -count 1 ./...
}

function unit-tests-hardhat() {
cd hardhat
npx hardhat test --network hardhat
}
Expand All @@ -298,8 +302,7 @@ function unit-tests() {
# see LOCAL_DEVELOPMENT.md
function integration-tests() {
load-local-env
cd test
go test -v -count 1 .
go test -v -tags="integration" -count 1 ./...
}

############################################################################
Expand Down
4 changes: 3 additions & 1 deletion test/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package main
//go:build integration

package main_test

import (
"fmt"
Expand Down

0 comments on commit bf71101

Please sign in to comment.