Skip to content

Commit

Permalink
Fix core/state_test tests failure (#2198)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann authored Oct 15, 2024
1 parent 9ed2acc commit 384fe56
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 0 additions & 2 deletions core/class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"reflect"
"testing"

"github.com/NethermindEth/juno/clients/feeder"
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 22 additions & 9 deletions core/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"reflect"
"testing"

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions core/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"reflect"
"testing"

"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 384fe56

Please sign in to comment.