From 5beff1e5c65b260d83876fa5833506d334ac7e11 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 7 Oct 2022 15:22:04 -0500 Subject: [PATCH 1/7] Add first e2e test for post-Merge indexing --- Makefile | 10 ++ go.mod | 12 ++ go.sum | 25 ++++ pkg/beaconclient/e2emerge_test.go | 200 ++++++++++++++++++++++++++++++ 4 files changed, 247 insertions(+) create mode 100644 pkg/beaconclient/e2emerge_test.go diff --git a/Makefile b/Makefile index 50155e1..7168909 100644 --- a/Makefile +++ b/Makefile @@ -111,6 +111,16 @@ system-test-local: --fail-on-pending --keep-going \ --trace +.PHONY: e2e-test-local +e2e-test-local: + go vet ./... + go fmt ./... + $(GINKGO) -r --label-filter e2e \ + --randomize-all --randomize-suites \ + --fail-on-pending --keep-going \ + --trace + + .PHONY: build build: go fmt ./... diff --git a/go.mod b/go.mod index 07b84fc..82db1ad 100644 --- a/go.mod +++ b/go.mod @@ -18,12 +18,20 @@ require ( ) require ( + github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/deckarep/golang-set v1.8.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/ethereum/go-ethereum v1.10.25 // indirect + github.com/go-ole/go-ole v1.2.1 // indirect + github.com/go-stack/stack v1.8.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/gorilla/websocket v1.4.2 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/holiman/uint256 v1.2.0 // indirect github.com/ipfs/bbloom v0.0.4 // indirect @@ -60,7 +68,10 @@ require ( github.com/prometheus/procfs v0.8.0 // indirect github.com/protolambda/bls12-381-util v0.0.0-20210720105258-a772f2aac13e // indirect github.com/rogpeppe/go-internal v1.8.0 // indirect + github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/tklauser/go-sysconf v0.3.5 // indirect + github.com/tklauser/numcpus v0.2.2 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.23.0 // indirect @@ -68,6 +79,7 @@ require ( golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect + gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect lukechampine.com/blake3 v1.1.7 // indirect ) diff --git a/go.sum b/go.sum index 4e7ac56..d83fdf1 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= +github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -51,6 +53,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= +github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= @@ -73,12 +77,19 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= +github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ethereum/go-ethereum v1.10.25 h1:5dFrKJDnYf8L6/5o42abCE6a9yJm9cs4EJVRyYMr55s= +github.com/ethereum/go-ethereum v1.10.25/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= @@ -95,7 +106,10 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= +github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= @@ -170,6 +184,8 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -444,6 +460,8 @@ github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OK github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= +github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= @@ -483,6 +501,10 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= +github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= +github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= +github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -688,6 +710,7 @@ golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -885,6 +908,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= +gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkg/beaconclient/e2emerge_test.go b/pkg/beaconclient/e2emerge_test.go new file mode 100644 index 0000000..a0b4dc1 --- /dev/null +++ b/pkg/beaconclient/e2emerge_test.go @@ -0,0 +1,200 @@ +package beaconclient_test + +import ( + "context" + "encoding/hex" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/pkg/errors" + zcommon "github.com/protolambda/zrnt/eth2/beacon/common" + "github.com/protolambda/zrnt/eth2/configs" + "github.com/protolambda/ztyp/tree" + log "github.com/sirupsen/logrus" + "github.com/vulcanize/ipld-eth-beacon-indexer/pkg/beaconclient" + "github.com/vulcanize/ipld-eth-beacon-indexer/pkg/database/sql" + "math/big" + "time" +) + +var ( + expectedPayloadStatement = `SELECT * FROM eth_beacon.signed_block WHERE + payload_block_number = ? AND + payload_block_hash = ? AND + payload_transactions_root = ?` +) +var _ = Describe("e2emerge", Label("e2e"), func() { + e2eConfig := TestConfig + e2eConfig.port = 5052 + e2eConfig.performBeaconStateProcessing = false + e2eConfig.performBeaconBlockProcessing = true + + level, _ := log.ParseLevel("debug") + log.SetLevel(level) + + Describe("Run the application against a merge testnet", func() { + Context("When we send a TX to geth", func() { + It("We should see TX as part of the ExecutionPayload in beacon", func() { + bc := setUpTest(e2eConfig, "0") + go bc.CaptureHead() + + tx, _ := sendTestTx() + log.Debugf("Sent ETH1 TX %s (Block No: %d, Block Hash: %s)", + tx.hash, tx.blockNo, tx.blockHash) + + var beaconBlock *beaconclient.DbSignedBeaconBlock + for i := 0; i < 30; i++ { + time.Sleep(time.Second) + record := checkForTx(bc.Db, tx) + if nil != record { + beaconBlock = record + log.Debugf("Found ETH1 TX %s in SignedBeaconBlock %d/%s", tx.hash, beaconBlock.Slot, beaconBlock.BlockRoot) + break + } + } + Expect(beaconBlock).ToNot(BeNil()) + }) + }) + }) +}) + +type SentTx struct { + hash string + raw []byte + blockNo uint64 + blockHash string + txIndex uint +} + +func (tx *SentTx) RawHex() string { + return "0x" + hex.EncodeToString(tx.raw) +} + +func checkForTx(db sql.Database, tx *SentTx) *beaconclient.DbSignedBeaconBlock { + sqlStatement := `SELECT * FROM eth_beacon.signed_block WHERE + payload_block_number = $1 AND + payload_block_hash = $2 AND + payload_transactions_root = $3` + + // We can pre-calculate the root and query on it because we are only sending a single TX at a time. + // Otherwise we would need to lookup the root by block num+hash, then do a proof that its txs + // root includes our TX. + var ptxs = zcommon.PayloadTransactions{tx.raw} + txRoot := ptxs.HashTreeRoot(configs.Mainnet, tree.GetHashFn()) + + var slot uint64 + var blockRoot, parentBlock, eth1DataBlockHash, mhKey string + + var blockNumber, timestamp uint64 + var blockHash, parentHash, stateRoot, receiptsRoot, transactionsRoot string + + err := db. + QueryRow(context.Background(), sqlStatement, tx.blockNo, tx.blockHash, "0x"+hex.EncodeToString(txRoot[:])). + Scan(&slot, &blockRoot, &parentBlock, ð1DataBlockHash, &mhKey, + &blockNumber, ×tamp, &blockHash, &parentHash, &stateRoot, + &receiptsRoot, &transactionsRoot) + if nil != err { + return nil + } + + return &beaconclient.DbSignedBeaconBlock{ + Slot: slot, + BlockRoot: blockRoot, + ParentBlock: parentBlock, + Eth1DataBlockHash: eth1DataBlockHash, + MhKey: mhKey, + ExecutionPayloadHeader: &beaconclient.DbExecutionPayloadHeader{ + BlockNumber: blockNumber, + Timestamp: timestamp, + BlockHash: blockHash, + ParentHash: parentHash, + StateRoot: stateRoot, + ReceiptsRoot: receiptsRoot, + TransactionsRoot: transactionsRoot, + }, + } +} + +func sendTestTx() (*SentTx, error) { + ctx := context.Background() + eth, err := createClient() + Expect(err).ToNot(HaveOccurred()) + + tx, err := sendTransaction( + ctx, + eth, + "0xe6ce22afe802caf5ff7d3845cec8c736ecc8d61f", + "0xe22AD83A0dE117bA0d03d5E94Eb4E0d80a69C62a", + 10, + "0x888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218", + ) + Expect(err).ToNot(HaveOccurred()) + + txBin, err := tx.MarshalBinary() + Expect(err).ToNot(HaveOccurred()) + + for i := 0; i <= 30; i++ { + time.Sleep(time.Second) + receipt, _ := eth.TransactionReceipt(ctx, tx.Hash()) + if nil != receipt { + return &SentTx{ + hash: tx.Hash().String(), + raw: txBin, + blockNo: receipt.BlockNumber.Uint64(), + blockHash: receipt.BlockHash.String(), + txIndex: receipt.TransactionIndex, + }, nil + } + } + + err = errors.New("Timed out waiting for TX.") + Expect(err).ToNot(HaveOccurred()) + return nil, err +} + +func createClient() (*ethclient.Client, error) { + return ethclient.Dial("http://localhost:8545") +} + +// sendTransaction sends a transaction with 1 ETH to a specified address. +func sendTransaction(ctx context.Context, eth *ethclient.Client, fromAddr string, toAddr string, amount int64, signingKey string) (*types.Transaction, error) { + var ( + from = common.HexToAddress(fromAddr) + to = common.HexToAddress(toAddr) + sk = crypto.ToECDSAUnsafe(common.FromHex(signingKey)) + value = big.NewInt(amount) + gasLimit = uint64(21000) + ) + // Retrieve the chainid (needed for signer) + chainid, err := eth.ChainID(ctx) + if err != nil { + return nil, err + } + // Retrieve the pending nonce + nonce, err := eth.PendingNonceAt(ctx, from) + if err != nil { + return nil, err + } + // Get suggested gas price + tipCap, _ := eth.SuggestGasTipCap(ctx) + feeCap, _ := eth.SuggestGasPrice(ctx) + // Create a new transaction + tx := types.NewTx( + &types.DynamicFeeTx{ + ChainID: chainid, + Nonce: nonce, + GasTipCap: tipCap, + GasFeeCap: feeCap, + Gas: gasLimit, + To: &to, + Value: value, + Data: nil, + }) + // Sign the transaction using our keys + signedTx, _ := types.SignTx(tx, types.NewLondonSigner(chainid), sk) + // Send the transaction to our node + return signedTx, eth.SendTransaction(ctx, signedTx) +} -- 2.45.2 From 89deaa2746baeb5ff3be1c446c9d30c00eebc55c Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 7 Oct 2022 15:33:57 -0500 Subject: [PATCH 2/7] Change titles --- pkg/beaconclient/e2emerge_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/beaconclient/e2emerge_test.go b/pkg/beaconclient/e2emerge_test.go index a0b4dc1..2eb32b8 100644 --- a/pkg/beaconclient/e2emerge_test.go +++ b/pkg/beaconclient/e2emerge_test.go @@ -35,9 +35,9 @@ var _ = Describe("e2emerge", Label("e2e"), func() { level, _ := log.ParseLevel("debug") log.SetLevel(level) - Describe("Run the application against a merge testnet", func() { + Describe("Run the application against a Merge testnet", func() { Context("When we send a TX to geth", func() { - It("We should see TX as part of the ExecutionPayload in beacon", func() { + It("We should see the TX included in the ExecutionPayload of a BeaconBlock", func() { bc := setUpTest(e2eConfig, "0") go bc.CaptureHead() -- 2.45.2 From c0736668c1f964932beec437c519f575f4ae17e8 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 7 Oct 2022 15:36:04 -0500 Subject: [PATCH 3/7] Remove unused variable. --- pkg/beaconclient/e2emerge_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/beaconclient/e2emerge_test.go b/pkg/beaconclient/e2emerge_test.go index 2eb32b8..759f29c 100644 --- a/pkg/beaconclient/e2emerge_test.go +++ b/pkg/beaconclient/e2emerge_test.go @@ -20,12 +20,6 @@ import ( "time" ) -var ( - expectedPayloadStatement = `SELECT * FROM eth_beacon.signed_block WHERE - payload_block_number = ? AND - payload_block_hash = ? AND - payload_transactions_root = ?` -) var _ = Describe("e2emerge", Label("e2e"), func() { e2eConfig := TestConfig e2eConfig.port = 5052 -- 2.45.2 From 7e45413e3d11ed3d61dea44404691240ad56b8d9 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 7 Oct 2022 15:42:54 -0500 Subject: [PATCH 4/7] Refactor --- pkg/beaconclient/e2emerge_test.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/beaconclient/e2emerge_test.go b/pkg/beaconclient/e2emerge_test.go index 759f29c..263be0f 100644 --- a/pkg/beaconclient/e2emerge_test.go +++ b/pkg/beaconclient/e2emerge_test.go @@ -39,16 +39,7 @@ var _ = Describe("e2emerge", Label("e2e"), func() { log.Debugf("Sent ETH1 TX %s (Block No: %d, Block Hash: %s)", tx.hash, tx.blockNo, tx.blockHash) - var beaconBlock *beaconclient.DbSignedBeaconBlock - for i := 0; i < 30; i++ { - time.Sleep(time.Second) - record := checkForTx(bc.Db, tx) - if nil != record { - beaconBlock = record - log.Debugf("Found ETH1 TX %s in SignedBeaconBlock %d/%s", tx.hash, beaconBlock.Slot, beaconBlock.BlockRoot) - break - } - } + beaconBlock := waitForTxToBeIndexed(bc.Db, tx) Expect(beaconBlock).ToNot(BeNil()) }) }) @@ -67,7 +58,21 @@ func (tx *SentTx) RawHex() string { return "0x" + hex.EncodeToString(tx.raw) } -func checkForTx(db sql.Database, tx *SentTx) *beaconclient.DbSignedBeaconBlock { +func waitForTxToBeIndexed(db sql.Database, tx *SentTx) *beaconclient.DbSignedBeaconBlock { + var beaconBlock *beaconclient.DbSignedBeaconBlock = nil + for i := 0; i < 30; i++ { + time.Sleep(time.Second) + record := lookForTxInDb(db, tx) + if nil != record { + beaconBlock = record + log.Debugf("Found ETH1 TX %s in SignedBeaconBlock %d/%s", tx.hash, beaconBlock.Slot, beaconBlock.BlockRoot) + break + } + } + return beaconBlock +} + +func lookForTxInDb(db sql.Database, tx *SentTx) *beaconclient.DbSignedBeaconBlock { sqlStatement := `SELECT * FROM eth_beacon.signed_block WHERE payload_block_number = $1 AND payload_block_hash = $2 AND -- 2.45.2 From 03806b2b8c4b554801260f7a3fdf501be0344995 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 7 Oct 2022 15:45:13 -0500 Subject: [PATCH 5/7] more refactor --- pkg/beaconclient/e2emerge_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/beaconclient/e2emerge_test.go b/pkg/beaconclient/e2emerge_test.go index 263be0f..18bb1b8 100644 --- a/pkg/beaconclient/e2emerge_test.go +++ b/pkg/beaconclient/e2emerge_test.go @@ -36,8 +36,6 @@ var _ = Describe("e2emerge", Label("e2e"), func() { go bc.CaptureHead() tx, _ := sendTestTx() - log.Debugf("Sent ETH1 TX %s (Block No: %d, Block Hash: %s)", - tx.hash, tx.blockNo, tx.blockHash) beaconBlock := waitForTxToBeIndexed(bc.Db, tx) Expect(beaconBlock).ToNot(BeNil()) @@ -139,13 +137,15 @@ func sendTestTx() (*SentTx, error) { time.Sleep(time.Second) receipt, _ := eth.TransactionReceipt(ctx, tx.Hash()) if nil != receipt { - return &SentTx{ + sentTx := &SentTx{ hash: tx.Hash().String(), raw: txBin, blockNo: receipt.BlockNumber.Uint64(), blockHash: receipt.BlockHash.String(), txIndex: receipt.TransactionIndex, - }, nil + } + log.Debugf("Sent ETH1 TX %s (Block No: %d, Block Hash: %s)", sentTx.hash, sentTx.blockNo, sentTx.blockHash) + return sentTx, nil } } -- 2.45.2 From cdc8ec70347c6b0955435dc058b6e9448882cc3c Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 7 Oct 2022 15:46:52 -0500 Subject: [PATCH 6/7] fmt --- pkg/beaconclient/e2emerge_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/beaconclient/e2emerge_test.go b/pkg/beaconclient/e2emerge_test.go index 18bb1b8..28c17c1 100644 --- a/pkg/beaconclient/e2emerge_test.go +++ b/pkg/beaconclient/e2emerge_test.go @@ -36,7 +36,6 @@ var _ = Describe("e2emerge", Label("e2e"), func() { go bc.CaptureHead() tx, _ := sendTestTx() - beaconBlock := waitForTxToBeIndexed(bc.Db, tx) Expect(beaconBlock).ToNot(BeNil()) }) -- 2.45.2 From 052e435676522763cadc746a8557603a90086d31 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 7 Oct 2022 15:56:07 -0500 Subject: [PATCH 7/7] Add comment --- pkg/beaconclient/e2emerge_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/beaconclient/e2emerge_test.go b/pkg/beaconclient/e2emerge_test.go index 28c17c1..d6c9073 100644 --- a/pkg/beaconclient/e2emerge_test.go +++ b/pkg/beaconclient/e2emerge_test.go @@ -119,6 +119,7 @@ func sendTestTx() (*SentTx, error) { eth, err := createClient() Expect(err).ToNot(HaveOccurred()) + //TODO: Pull from test config / env. tx, err := sendTransaction( ctx, eth, -- 2.45.2