Skip to content

Commit 48c2b2e

Browse files
committed
plugin/evm/header/extra_test.go: TestPredicateBytesExtra
1 parent b525a63 commit 48c2b2e

File tree

1 file changed

+39
-56
lines changed

1 file changed

+39
-56
lines changed

plugin/evm/header/extra_test.go

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -609,74 +609,68 @@ func TestVerifyExtra(t *testing.T) {
609609
}
610610
}
611611

612-
func TestPredicateBytesFromExtra(t *testing.T) {
612+
func TestPredicateBytesExtra(t *testing.T) {
613613
tests := []struct {
614-
name string
615-
rules extras.AvalancheRules
616-
extra []byte
617-
expected []byte
614+
name string
615+
rules extras.AvalancheRules
616+
extra []byte
617+
predicate []byte
618+
wantExtraWithPredicate []byte
619+
wantPredicateBytes []byte
618620
}{
619621
{
620-
name: "empty_extra",
621-
extra: nil,
622-
expected: nil,
623-
},
624-
{
625-
name: "too_short",
626-
extra: make([]byte, ap3.WindowSize-1),
627-
expected: nil,
628-
},
629-
{
630-
name: "empty_predicate",
631-
extra: make([]byte, ap3.WindowSize),
632-
expected: nil,
633-
},
634-
{
635-
name: "non_empty_predicate",
636-
extra: []byte{
637-
ap3.WindowSize: 5,
638-
},
639-
expected: []byte{5},
622+
name: "empty_extra_predicate",
623+
extra: nil,
624+
predicate: nil,
625+
wantExtraWithPredicate: make([]byte, ap3.WindowSize),
626+
wantPredicateBytes: nil,
640627
},
641628
{
642-
name: "fortuna_empty_extra",
629+
name: "empty_extra_predicate_fortuna",
643630
rules: extras.AvalancheRules{
644631
IsFortuna: true,
645632
},
646-
extra: nil,
647-
expected: nil,
633+
extra: nil,
634+
predicate: nil,
635+
wantExtraWithPredicate: make([]byte, acp176.StateSize),
636+
wantPredicateBytes: nil,
648637
},
649638
{
650-
name: "fortuna_too_short",
651-
rules: extras.AvalancheRules{
652-
IsFortuna: true,
639+
name: "extra_too_short",
640+
extra: []byte{
641+
0: 1,
642+
ap3.WindowSize - 1: 0,
653643
},
654-
extra: make([]byte, acp176.StateSize-1),
655-
expected: nil,
656-
},
657-
{
658-
name: "fortuna_empty_predicate",
659-
rules: extras.AvalancheRules{
660-
IsFortuna: true,
644+
predicate: []byte{2},
645+
wantExtraWithPredicate: []byte{
646+
0: 1,
647+
ap3.WindowSize: 2,
661648
},
662-
extra: make([]byte, acp176.StateSize),
663-
expected: nil,
649+
wantPredicateBytes: []byte{2},
664650
},
665651
{
666-
name: "fortuna_non_empty_predicate",
652+
name: "extra_too_short_fortuna",
667653
rules: extras.AvalancheRules{
668654
IsFortuna: true,
669655
},
670656
extra: []byte{
671-
acp176.StateSize: 5,
657+
0: 1,
658+
acp176.StateSize - 1: 0,
659+
},
660+
predicate: []byte{2},
661+
wantExtraWithPredicate: []byte{
662+
0: 1,
663+
acp176.StateSize: 2,
672664
},
673-
expected: []byte{5},
665+
wantPredicateBytes: []byte{2},
674666
},
675667
}
676668
for _, test := range tests {
677669
t.Run(test.name, func(t *testing.T) {
678-
got := PredicateBytesFromExtra(test.rules, test.extra)
679-
require.Equal(t, test.expected, got)
670+
got := SetPredicateBytesInExtra(test.rules, test.extra, test.predicate)
671+
require.Equal(t, test.wantExtraWithPredicate, got)
672+
got = PredicateBytesFromExtra(test.rules, test.extra)
673+
require.Equal(t, test.wantPredicateBytes, got)
680674
})
681675
}
682676
}
@@ -689,17 +683,6 @@ func TestSetPredicateBytesInExtra(t *testing.T) {
689683
predicate []byte
690684
want []byte
691685
}{
692-
{
693-
name: "empty_extra_predicate",
694-
want: make([]byte, ap3.WindowSize),
695-
},
696-
{
697-
name: "empty_extra_predicate_fortuna",
698-
rules: extras.AvalancheRules{
699-
IsFortuna: true,
700-
},
701-
want: make([]byte, acp176.StateSize),
702-
},
703686
{
704687
name: "extra_too_short",
705688
extra: []byte{1},

0 commit comments

Comments
 (0)