From e6c52e18a6c1415919a0189c3622ffc9984c6c33 Mon Sep 17 00:00:00 2001 From: battlmonstr Date: Mon, 16 Oct 2023 15:03:18 +0200 Subject: [PATCH] tests: test that erigon can be used as a library --- .github/workflows/test-integration.yml | 5 +++++ Makefile | 18 ++++++++++-------- tests/erigon-ext-test/.gitignore | 2 ++ tests/erigon-ext-test/go.mod.template | 9 +++++++++ tests/erigon-ext-test/main.go | 18 ++++++++++++++++++ tests/erigon-ext-test/test.sh | 10 ++++++++++ 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 tests/erigon-ext-test/.gitignore create mode 100644 tests/erigon-ext-test/go.mod.template create mode 100644 tests/erigon-ext-test/main.go create mode 100755 tests/erigon-ext-test/test.sh diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index ec526d3f3fa..dd90ea72721 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -29,6 +29,11 @@ jobs: - name: test-integration run: make test-integration + - name: Test erigon as a library + env: + GIT_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }} + run: make test-erigon-ext GIT_COMMIT=$GIT_COMMIT + # name: history-v3-test-integration # run: make test3-integration diff --git a/Makefile b/Makefile index 7994a2faefb..9b1e49f16fc 100644 --- a/Makefile +++ b/Makefile @@ -140,22 +140,24 @@ db-tools: rm -rf vendor @echo "Run \"$(GOBIN)/mdbx_stat -h\" to get info about mdbx db file." -## test: run unit tests with a 100s timeout -test: +test-erigon-lib: @cd erigon-lib && $(MAKE) test + +test-erigon-ext: + @cd tests/erigon-ext-test && ./test.sh $(GIT_COMMIT) + +## test: run unit tests with a 100s timeout +test: test-erigon-lib $(GOTEST) --timeout 10m -test3: - @cd erigon-lib && $(MAKE) test +test3: test-erigon-lib $(GOTEST) --timeout 10m -tags $(BUILD_TAGS),e3 ## test-integration: run integration tests with a 30m timeout -test-integration: - @cd erigon-lib && $(MAKE) test +test-integration: test-erigon-lib $(GOTEST) --timeout 240m -tags $(BUILD_TAGS),integration -test3-integration: - @cd erigon-lib && $(MAKE) test +test3-integration: test-erigon-lib $(GOTEST) --timeout 240m -tags $(BUILD_TAGS),integration,e3 ## lint-deps: install lint dependencies diff --git a/tests/erigon-ext-test/.gitignore b/tests/erigon-ext-test/.gitignore new file mode 100644 index 00000000000..6db33941e3f --- /dev/null +++ b/tests/erigon-ext-test/.gitignore @@ -0,0 +1,2 @@ +go.mod +go.sum diff --git a/tests/erigon-ext-test/go.mod.template b/tests/erigon-ext-test/go.mod.template new file mode 100644 index 00000000000..515b3b14281 --- /dev/null +++ b/tests/erigon-ext-test/go.mod.template @@ -0,0 +1,9 @@ +module example.com/erigon-ext-test + +go 1.20 + +require github.com/ledgerwatch/erigon $COMMIT_SHA + +replace github.com/ledgerwatch/erigon-lib => github.com/ledgerwatch/erigon/erigon-lib $COMMIT_SHA + +require github.com/ethereum/go-ethereum v1.13.3 diff --git a/tests/erigon-ext-test/main.go b/tests/erigon-ext-test/main.go new file mode 100644 index 00000000000..b8322f5973e --- /dev/null +++ b/tests/erigon-ext-test/main.go @@ -0,0 +1,18 @@ +package main + +import ( + geth_params "github.com/ethereum/go-ethereum/params" + // geth_crypto "github.com/ethereum/go-ethereum/crypto" + erigon_lib_common "github.com/ledgerwatch/erigon-lib/common" + erigon_crypto "github.com/ledgerwatch/erigon/crypto" + erigon_params "github.com/ledgerwatch/erigon/params" +) + +func main() { + println("Erigon version: ", erigon_params.Version) + println("geth version: ", geth_params.Version) + println("Erigon lib common eth Wei: ", erigon_lib_common.Wei) + println("Erigon crypto secp256k1 S256 BitSize: ", erigon_crypto.S256().Params().BitSize) + // not working due to duplicate symbols errors + // println("geth crypto secp256k1 S256 BitSize: ", geth_crypto.S256().Params().BitSize) +} diff --git a/tests/erigon-ext-test/test.sh b/tests/erigon-ext-test/test.sh new file mode 100755 index 00000000000..362028e5fe7 --- /dev/null +++ b/tests/erigon-ext-test/test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +COMMIT_SHA="$1" + +sed "s/\$COMMIT_SHA/$COMMIT_SHA/" go.mod.template > go.mod + +rm -f go.sum +go mod tidy + +go run main.go