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

Add tests into ci #37

Merged
merged 9 commits into from
Nov 26, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ on:
default: ""

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
env:
BEACONCHAIN_URL: ${{ secrets.BEACONCHAIN_URL }}
RPC_URL: ${{ secrets.RPC_URL }}
WS_URL: ${{ secrets.WS_URL }}
IPFS_URL: ${{ secrets.IPFS_URL }}
LOG_LEVEL: DEBUG

steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v4

# Run integration tests
- name: Run Integration Tests
run: |
echo "Running Integration Tests"
go test -v --race -tags=integration ./...

release:
name: Release and Publish Docker Image
needs: test # Ensure the test job runs successfully first
runs-on: ubuntu-latest

steps:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run Tests

on:
pull_request:
branches:
- main

workflow_dispatch:

env:
LOG_LEVEL: DEBUG

jobs:
tests:
runs-on: ubuntu-latest
env:
BEACONCHAIN_URL: ${{ secrets.BEACONCHAIN_URL }}
RPC_URL: ${{ secrets.RPC_URL }}
WS_URL: ${{ secrets.WS_URL }}
IPFS_URL: ${{ secrets.IPFS_URL }}
LOG_LEVEL: DEBUG

steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v4

# Run integration tests
- name: Run Integration Tests
run: |
echo "Running Integration Tests"
NETWORK=holesky go test -v -tags=integration ./...
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,34 @@ func setupBeaconchainAdapter(t *testing.T) *beaconchain.BeaconchainAdapter {
}

func TestGetValidatorStatusIntegration(t *testing.T) {
t.Skip()
adapter := setupBeaconchainAdapter(t)

// Test an active validator
pubkeyActive := "0x800000b3884235f70b06fec68c19642fc9e81e34fbe7f1c0ae156b8b45860dfe5ac71037ae561c2a759ba83401488e18"
status, err := adapter.GetValidatorStatus(pubkeyActive)
assert.NoError(t, err)
assert.Equal(t, domain.StatusActiveOngoing, status)

// Test a slashed validator
pubkeySlashed := "0x8d6f381707c822288503112982628ff01cf9d6fa7753bd6b8a9909db5bd7d0b44b36709e4142e137dbed4b0c1bd23b2c"
status, err = adapter.GetValidatorStatus(pubkeySlashed)
pubkeyExited := "0x972255d9a5085d082d485f1e17999b38967e022057aba66a477cd93bce5cfa980bc42df82b208987ed46b9cdbc7b5fcb"
status, err := adapter.GetValidatorStatus(pubkeyExited)
assert.NoError(t, err)
assert.Equal(t, domain.StatusExitedSlashed, status)
assert.Equal(t, domain.StatusExitedUnslashed, status)
}

func TestPostStateValidatorsIntegration(t *testing.T) {
t.Skip()
adapter := setupBeaconchainAdapter(t)

// Test with active and slashed validators
ids := []string{
"0x800000b3884235f70b06fec68c19642fc9e81e34fbe7f1c0ae156b8b45860dfe5ac71037ae561c2a759ba83401488e18",
"0x8d6f381707c822288503112982628ff01cf9d6fa7753bd6b8a9909db5bd7d0b44b36709e4142e137dbed4b0c1bd23b2c",
"1802081",
}
response, err := adapter.PostStateValidators("finalized", ids, nil)
assert.NoError(t, err)
assert.Len(t, response.Data, 2)
assert.Len(t, response.Data, 1)

// Validate the statuses
assert.Equal(t, domain.StatusActiveOngoing, domain.ValidatorStatus(response.Data[0].Status))
assert.Equal(t, domain.StatusExitedSlashed, domain.ValidatorStatus(response.Data[1].Status))
assert.Equal(t, domain.StatusExitedUnslashed, domain.ValidatorStatus(response.Data[0].Status))
}

func TestSubmitPoolVoluntaryExitIntegration(t *testing.T) {
t.Skip()
adapter := setupBeaconchainAdapter(t)

// Example voluntary exit submission (modify epoch and validatorIndex accordingly)
Expand All @@ -65,6 +60,7 @@ func TestSubmitPoolVoluntaryExitIntegration(t *testing.T) {
}

func TestGetStateForkIntegration(t *testing.T) {
t.Skip()
adapter := setupBeaconchainAdapter(t)

// Retrieve fork for "head"
Expand All @@ -75,6 +71,7 @@ func TestGetStateForkIntegration(t *testing.T) {
}

func TestGetGenesisIntegration(t *testing.T) {
t.Skip()
adapter := setupBeaconchainAdapter(t)

// Retrieve genesis data
Expand All @@ -85,6 +82,7 @@ func TestGetGenesisIntegration(t *testing.T) {
}

func TestGetBlockHeaderIntegration(t *testing.T) {
t.Skip()
adapter := setupBeaconchainAdapter(t)

// Retrieve block header for "finalized"
Expand All @@ -95,6 +93,7 @@ func TestGetBlockHeaderIntegration(t *testing.T) {
}

func TestGetEpochHeaderIntegration(t *testing.T) {
t.Skip()
adapter := setupBeaconchainAdapter(t)

// Retrieve epoch header for "finalized"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func setupCsFeeDistributorImplAdapter(t *testing.T) (*csfeedistributorimpl.CsFee

// ScanDistributionLogUpdatedEventsIntegration tests scanning for DistributionLogUpdated events
func TestScanDistributionLogUpdatedEventsIntegration(t *testing.T) {
t.Skip()
adapter, err := setupCsFeeDistributorImplAdapter(t)
assert.NoError(t, err)

Expand Down
3 changes: 0 additions & 3 deletions internal/adapters/ipfs/ipfs_adapter_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ func TestFetchAndParseIpfs(t *testing.T) {
t.Fatalf("failed to fetch and parse IPFS data: %v", err)
}

// Print the fetched report for manual inspection (optional)
t.Logf("Fetched report: %+v", report)

// Assertions to validate fields based on expected structure

// Check if `Frame` has been populated
Expand Down
2 changes: 1 addition & 1 deletion internal/adapters/storage/operators_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestGetOperatorIds_InvalidOperatorId(t *testing.T) {
operatorIDs, err := storageAdapter.GetOperatorIds()
assert.Error(t, err)
assert.Nil(t, operatorIDs)
assert.EqualError(t, err, "failed to convert operator ID to big.Int")
assert.EqualError(t, err, "failed to convert operator ID invalid to big.Int")
}

// TestDeleteOperator_ExistingOperator tests deleting an existing operator ID.
Expand Down
18 changes: 7 additions & 11 deletions internal/adapters/vebo/vebo_adapter_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func setupVeboAdapter(t *testing.T) (*vebo.VeboAdapter, *mocks.MockStoragePort,
mockStorage := new(mocks.MockStoragePort)

// Define initial operator IDs as required by the test
mockStorage.On("GetOperatorIds").Return([]*big.Int{big.NewInt(20)}, nil)
mockStorage.On("GetOperatorIds").Return([]*big.Int{big.NewInt(2535)}, nil)

veboAddress := common.HexToAddress("0x0De4Ea0184c2ad0BacA7183356Aea5B8d5Bf5c6e")
veboAddress := common.HexToAddress("0xffDDF7025410412deaa05E3E1cE68FE53208afcb")

// Initialize the adapter with the mock storage
adapter, err := vebo.NewVeboAdapter(wsURL, veboAddress, mockStorage)
Expand All @@ -44,8 +44,8 @@ func TestScanVeboValidatorExitRequestEventIntegration(t *testing.T) {
assert.NoError(t, err)

// Set the start and end blocks for the scan
start := uint64(21071257)
end := uint64(21071259)
start := uint64(2689810)
end := uint64(2812210)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand Down Expand Up @@ -77,13 +77,9 @@ func TestScanVeboValidatorExitRequestEventIntegration(t *testing.T) {

// Assertions for the expected events
assert.NoError(t, err)
assert.Contains(t, foundEvents, "370637")
assert.Equal(t, "b07c5cc5abd773d24c460140f872d24fb6584027626a4cba7b43e4f79f22c7b4846ea55d11ba96a322ba663c55cf3523", foundEvents["370637"].ValidatorPubkey)
assert.Equal(t, uint64(21071258), foundEvents["370637"].BlockNumber)

assert.Contains(t, foundEvents, "370638")
assert.Equal(t, "92404310ad54447f6ab3277351a0da37f9b75696409056e855cfbe9838c649def1ca24cba994f6394f436c940d4cc3bc", foundEvents["370638"].ValidatorPubkey)
assert.Equal(t, uint64(21071258), foundEvents["370638"].BlockNumber)
assert.Contains(t, foundEvents, "1802081")
assert.Equal(t, "972255d9a5085d082d485f1e17999b38967e022057aba66a477cd93bce5cfa980bc42df82b208987ed46b9cdbc7b5fcb", foundEvents["1802081"].ValidatorPubkey)
assert.Equal(t, uint64(2790523), foundEvents["1802081"].BlockNumber)

// Ensure all expected mock calls were made
mockStorage.AssertCalled(t, "GetOperatorIds") // Ensure GetOperatorIds was actually called
Expand Down

This file was deleted.

Loading