From e6289b1b86fe58f35f4756a41b38214e737d41e0 Mon Sep 17 00:00:00 2001 From: tsinghuacoder Date: Fri, 11 Apr 2025 15:52:25 +0800 Subject: [PATCH] refactor: use slices.Equal to simplify code Signed-off-by: tsinghuacoder --- common/uint160_test.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/common/uint160_test.go b/common/uint160_test.go index ed8f0d31..989ee9ca 100644 --- a/common/uint160_test.go +++ b/common/uint160_test.go @@ -3,6 +3,7 @@ package common import ( "encoding/hex" "encoding/json" + "slices" "testing" ) @@ -29,7 +30,7 @@ func TestMarshalJSON(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - if !bytesEqual(bytes, expected) { + if !slices.Equal(bytes, expected) { t.Fatalf("Expected %v, got %v", expected, bytes) } @@ -38,7 +39,7 @@ func TestMarshalJSON(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - if !bytesEqual(bytes, expected) { + if !slices.Equal(bytes, expected) { t.Fatalf("Expected %v, got %v", expected, bytes) } @@ -61,22 +62,10 @@ func TestUnmarshalJSON(t *testing.T) { if err != nil { t.Fatal(err) } - if !bytesEqual(f.ToArray(), expected) { + if !slices.Equal(f.ToArray(), expected) { t.Fatalf("Expected %v, got %v", expected, f.ToArray()) } // TODO: If possible, create a scenario where ToScriptHash returns an error // and verify that UnmarshalJSON also returns this error. } - -func bytesEqual(a, b []byte) bool { - if len(a) != len(b) { - return false - } - for i, v := range a { - if v != b[i] { - return false - } - } - return true -}