Skip to content

Commit

Permalink
rlp: improve tests for Split functions (ethereum#26200)
Browse files Browse the repository at this point in the history
This PR improves and extends the tests a bit
  • Loading branch information
therainisme authored Nov 17, 2022
1 parent 12df456 commit 722bb21
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions rlp/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,35 @@ func TestCountValues(t *testing.T) {
}
}

func TestSplitTypes(t *testing.T) {
if _, _, err := SplitString(unhex("C100")); err != ErrExpectedString {
t.Errorf("SplitString returned %q, want %q", err, ErrExpectedString)
}
if _, _, err := SplitList(unhex("01")); err != ErrExpectedList {
t.Errorf("SplitString returned %q, want %q", err, ErrExpectedList)
func TestSplitString(t *testing.T) {
for i, test := range []string{
"C0",
"C100",
"C3010203",
"C88363617483646F67",
"F8384C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E7365637465747572206164697069736963696E6720656C6974",
} {
if _, _, err := SplitString(unhex(test)); !errors.Is(err, ErrExpectedString) {
t.Errorf("test %d: error mismatch: have %q, want %q", i, err, ErrExpectedString)
}
}
if _, _, err := SplitList(unhex("81FF")); err != ErrExpectedList {
t.Errorf("SplitString returned %q, want %q", err, ErrExpectedList)
}

func TestSplitList(t *testing.T) {
for i, test := range []string{
"80",
"00",
"01",
"8180",
"81FF",
"820400",
"83636174",
"83646F67",
"B8384C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E7365637465747572206164697069736963696E6720656C6974",
} {
if _, _, err := SplitList(unhex(test)); !errors.Is(err, ErrExpectedList) {
t.Errorf("test %d: error mismatch: have %q, want %q", i, err, ErrExpectedList)
}
}
}

Expand Down

0 comments on commit 722bb21

Please sign in to comment.