From 384fe56ca7f20760122de8558181f11d24ee6abb Mon Sep 17 00:00:00 2001 From: Ng Wei Han <47109095+weiihann@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:48:39 +0800 Subject: [PATCH] Fix core/state_test tests failure (#2198) --- core/class_test.go | 2 -- core/state_test.go | 31 ++++++++++++++++++++++--------- core/transaction_test.go | 2 -- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/core/class_test.go b/core/class_test.go index a0aad1464b..599651202c 100644 --- a/core/class_test.go +++ b/core/class_test.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "reflect" "testing" "github.com/NethermindEth/juno/clients/feeder" @@ -168,7 +167,6 @@ func TestClassEncoding(t *testing.T) { func checkClassSymmetry(t *testing.T, input core.Class) { t.Helper() - require.NoError(t, encoder.RegisterType(reflect.TypeOf(input))) data, err := encoder.Marshal(input) require.NoError(t, err) diff --git a/core/state_test.go b/core/state_test.go index c9333b1c2a..6b96d64b3b 100644 --- a/core/state_test.go +++ b/core/state_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "os" "reflect" "testing" @@ -25,6 +26,27 @@ 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) @@ -380,15 +402,6 @@ func TestClass(t *testing.T) { cairo1Class, err := gw.Class(context.Background(), cairo0Hash) require.NoError(t, err) - err = encoder.RegisterType(reflect.TypeOf(cairo0Class)) - if err != nil { - require.Contains(t, err.Error(), "already exists in TagSet") - } - err = encoder.RegisterType(reflect.TypeOf(cairo1Hash)) - if err != nil { - require.Contains(t, err.Error(), "already exists in TagSet") - } - state := core.NewState(txn) su0, err := gw.StateUpdate(context.Background(), 0) require.NoError(t, err) diff --git a/core/transaction_test.go b/core/transaction_test.go index 9b23ded7bd..5121e30a0d 100644 --- a/core/transaction_test.go +++ b/core/transaction_test.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "errors" "fmt" - "reflect" "testing" "github.com/Masterminds/semver/v3" @@ -127,7 +126,6 @@ func TestTransactionEncoding(t *testing.T) { func checkTransactionSymmetry(t *testing.T, input core.Transaction) { t.Helper() - require.NoError(t, encoder.RegisterType(reflect.TypeOf(input))) data, err := encoder.Marshal(input) require.NoError(t, err)