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

Use encoder/registry to initialize encoder types #2359

Merged
merged 1 commit into from
Jan 6, 2025
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
1 change: 0 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ type Blockchain struct {
}

func New(database db.DB, network *utils.Network, pendingBlockFn func() *core.Block) *Blockchain {
RegisterCoreTypesToEncoder()
return &Blockchain{
database: database,
network: network,
Expand Down
5 changes: 5 additions & 0 deletions blockchain/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package blockchain_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
5 changes: 5 additions & 0 deletions cmd/juno/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
1 change: 1 addition & 0 deletions cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"syscall"
"time"

_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/jemalloc"
"github.com/NethermindEth/juno/node"
"github.com/NethermindEth/juno/utils"
Expand Down
5 changes: 5 additions & 0 deletions core/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package core_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
24 changes: 0 additions & 24 deletions core/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"reflect"
"testing"

"github.com/NethermindEth/juno/clients/feeder"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/db/pebble"
"github.com/NethermindEth/juno/encoder"
adaptfeeder "github.com/NethermindEth/juno/starknetdata/feeder"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
Expand All @@ -26,27 +23,6 @@ var (
su1FirstDeployedAddress = *_su1FirstDeployedAddress
)

func TestMain(m *testing.M) {
txTypes := []core.Transaction{
&core.DeclareTransaction{},
&core.DeployTransaction{},
&core.InvokeTransaction{},
&core.L1HandlerTransaction{},
&core.DeployAccountTransaction{},
}

for _, tx := range txTypes {
_ = encoder.RegisterType(reflect.TypeOf(tx))
}

_ = encoder.RegisterType(reflect.TypeOf(core.Cairo0Class{}))
_ = encoder.RegisterType(reflect.TypeOf(core.Cairo1Class{}))

code := m.Run()

os.Exit(code)
}

func TestUpdate(t *testing.T) {
client := feeder.NewTestClient(t, &utils.Mainnet)
gw := adaptfeeder.New(client)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blockchain
package registry

import (
"reflect"
Expand All @@ -10,7 +10,8 @@ import (

var once sync.Once

func RegisterCoreTypesToEncoder() {
//nolint:gochecknoinits
func init() {
once.Do(func() {
types := []reflect.Type{
reflect.TypeOf(core.DeclareTransaction{}),
Expand Down
5 changes: 5 additions & 0 deletions migration/init_pkg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package migration

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
1 change: 0 additions & 1 deletion migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ func relocateContractStorageRootKeys(txn db.Transaction, _ *utils.Network) error

// recalculateBloomFilters updates bloom filters in block headers to match what the most recent implementation expects
func recalculateBloomFilters(txn db.Transaction, _ *utils.Network) error {
blockchain.RegisterCoreTypesToEncoder()
for blockNumber := uint64(0); ; blockNumber++ {
block, err := blockchain.BlockByNumber(txn, blockNumber)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion migration/migration_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ func TestMigrateTrieRootKeysFromBitsetToTrieKeys(t *testing.T) {
}

func TestMigrateCairo1CompiledClass(t *testing.T) {
blockchain.RegisterCoreTypesToEncoder()
txn := db.NewMemTransaction()

key := []byte("key")
Expand Down
5 changes: 5 additions & 0 deletions node/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package node_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
5 changes: 5 additions & 0 deletions plugin/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package plugin_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
5 changes: 5 additions & 0 deletions sync/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sync_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
5 changes: 5 additions & 0 deletions vm/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package vm_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
)
8 changes: 0 additions & 8 deletions vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package vm
import (
"context"
"os"
"reflect"
"testing"

"github.com/NethermindEth/juno/clients/feeder"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db/pebble"
"github.com/NethermindEth/juno/encoder"
adaptfeeder "github.com/NethermindEth/juno/starknetdata/feeder"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
Expand All @@ -33,8 +31,6 @@ func TestV0Call(t *testing.T) {
simpleClass, err := gw.Class(context.Background(), classHash)
require.NoError(t, err)

require.NoError(t, encoder.RegisterType(reflect.TypeOf(core.Cairo0Class{})))

testState := core.NewState(txn)
require.NoError(t, testState.Update(0, &core.StateUpdate{
OldRoot: &felt.Zero,
Expand Down Expand Up @@ -95,8 +91,6 @@ func TestV1Call(t *testing.T) {
simpleClass, err := gw.Class(context.Background(), classHash)
require.NoError(t, err)

require.NoError(t, encoder.RegisterType(reflect.TypeOf(core.Cairo1Class{})))

testState := core.NewState(txn)
require.NoError(t, testState.Update(0, &core.StateUpdate{
OldRoot: &felt.Zero,
Expand Down Expand Up @@ -165,8 +159,6 @@ func TestCall_MaxSteps(t *testing.T) {
simpleClass, err := gw.Class(context.Background(), classHash)
require.NoError(t, err)

encoder.RegisterType(reflect.TypeOf(core.Cairo0Class{})) //nolint:errcheck

testState := core.NewState(txn)
require.NoError(t, testState.Update(0, &core.StateUpdate{
OldRoot: &felt.Zero,
Expand Down
Loading