parent
9fc97e43b0
commit
2876ac5d99
@ -0,0 +1,112 @@ |
||||
// Copyright 2014 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Package types contains data types related to Ethereum consensus.
|
||||
package types |
||||
|
||||
import ( |
||||
"bytes" |
||||
"testing" |
||||
) |
||||
|
||||
var ( |
||||
pat48Hex55 = []byte{ |
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, |
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, |
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, |
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, |
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, |
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, |
||||
} |
||||
pat48HexAA = []byte{ |
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
||||
} |
||||
pat48Pi = []byte{ |
||||
0x03, 0x14, 0x15, 0x92, 0x65, 0x35, 0x89, 0x79, |
||||
0x32, 0x38, 0x46, 0x26, 0x43, 0x38, 0x32, 0x79, |
||||
0x50, 0x28, 0x84, 0x19, 0x71, 0x69, 0x39, 0x93, |
||||
0x75, 0x10, 0x58, 0x20, 0x97, 0x49, 0x44, 0x59, |
||||
0x23, 0x07, 0x81, 0x64, 0x06, 0x28, 0x62, 0x08, |
||||
0x99, 0x86, 0x28, 0x03, 0x48, 0x25, 0x34, 0x21, |
||||
} |
||||
pat48E = []byte{ |
||||
0x02, 0x71, 0x82, 0x81, 0x82, 0x84, 0x59, 0x04, |
||||
0x52, 0x35, 0x36, 0x02, 0x87, 0x47, 0x13, 0x52, |
||||
0x66, 0x24, 0x97, 0x75, 0x72, 0x47, 0x09, 0x36, |
||||
0x99, 0x95, 0x95, 0x74, 0x96, 0x69, 0x67, 0x62, |
||||
0x77, 0x24, 0x07, 0x66, 0x30, 0x35, 0x35, 0x47, |
||||
0x59, 0x45, 0x71, 0x38, 0x21, 0x78, 0x52, 0x51, |
||||
} |
||||
) |
||||
|
||||
func TestBlock_SetPrepareSig(t *testing.T) { |
||||
tests := []struct { |
||||
name string |
||||
sig []byte |
||||
signers []byte |
||||
}{ |
||||
{"55AA", pat48Hex55, pat48HexAA}, |
||||
{"AA55", pat48HexAA, pat48Hex55}, |
||||
{"PiE", pat48Pi, pat48E}, |
||||
{"EPi", pat48E, pat48Pi}, |
||||
} |
||||
for _, tt := range tests { |
||||
t.Run(tt.name, func(t *testing.T) { |
||||
b := &Block{header: &Header{}} |
||||
b.SetPrepareSig(tt.sig, tt.signers) |
||||
if !bytes.Equal(tt.sig, b.header.PrepareSignature[:]) { |
||||
t.Errorf("signature mismatch: expected %+v, actual %+v", |
||||
tt.sig, b.header.PrepareSignature) |
||||
} |
||||
if !bytes.Equal(tt.signers, b.header.PrepareBitmap) { |
||||
t.Errorf("signature mismatch: expected %+v, actual %+v", |
||||
tt.signers, b.header.PrepareBitmap) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
||||
func TestBlock_SetCommitSig(t *testing.T) { |
||||
tests := []struct { |
||||
name string |
||||
sig []byte |
||||
signers []byte |
||||
}{ |
||||
{"5AAa", pat48Hex55, pat48HexAA}, |
||||
{"AA55", pat48HexAA, pat48Hex55}, |
||||
{"PiE", pat48Pi, pat48E}, |
||||
{"EPi", pat48E, pat48Pi}, |
||||
} |
||||
for _, tt := range tests { |
||||
t.Run(tt.name, func(t *testing.T) { |
||||
b := &Block{header: &Header{}} |
||||
b.SetCommitSig(tt.sig, tt.signers) |
||||
if !bytes.Equal(tt.sig, b.header.CommitSignature[:]) { |
||||
t.Errorf("signature mismatch: expected %+v, actual %+v", |
||||
tt.sig, b.header.CommitSignature) |
||||
} |
||||
if !bytes.Equal(tt.signers, b.header.CommitBitmap) { |
||||
t.Errorf("signature mismatch: expected %+v, actual %+v", |
||||
tt.signers, b.header.CommitBitmap) |
||||
} |
||||
}) |
||||
} |
||||
} |
Loading…
Reference in new issue