|
|
|
@ -19,9 +19,17 @@ package types |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"reflect" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
|
"github.com/harmony-one/taggedrlp" |
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/block" |
|
|
|
|
blockfactory "github.com/harmony-one/harmony/block/factory" |
|
|
|
|
blockif "github.com/harmony-one/harmony/block/interface" |
|
|
|
|
v0 "github.com/harmony-one/harmony/block/v0" |
|
|
|
|
v1 "github.com/harmony-one/harmony/block/v1" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
@ -110,3 +118,675 @@ func TestBlock_SetLastCommitSig(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestBlock_DecodeRLP(t *testing.T) { |
|
|
|
|
type args struct { |
|
|
|
|
s *rlp.Stream |
|
|
|
|
} |
|
|
|
|
tests := []struct { |
|
|
|
|
name string |
|
|
|
|
args args |
|
|
|
|
wantErr bool |
|
|
|
|
wantHeaderType reflect.Type |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
"v0", |
|
|
|
|
args{s: rlp.NewStream(bytes.NewBuffer([]byte{ |
|
|
|
|
// BEGIN 591-byte extblock
|
|
|
|
|
0xf9, 0x02, 0x4f, |
|
|
|
|
// BEGIN 586-byte Header
|
|
|
|
|
0xf9, 0x02, 0x4a, |
|
|
|
|
0xa0, // 32-byte ParentHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x94, // 20-byte Coinbase
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte Root
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte TxHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte ReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xb9, 0x01, 0x00, // 256-byte Bloom
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte Number
|
|
|
|
|
0x80, // 0-byte GasLimit
|
|
|
|
|
0x80, // 0-byte GasUsed
|
|
|
|
|
0x80, // 0-byte Time
|
|
|
|
|
0x80, // 0-byte Extra
|
|
|
|
|
0xa0, // 32-byte MixDigest
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte ViewID
|
|
|
|
|
0x80, // 0-byte Epoch
|
|
|
|
|
0x80, // 0-byte ShardID
|
|
|
|
|
0xb8, 0x60, // 96-byte LastCommitSignature
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte LastCommitBitmap
|
|
|
|
|
0xa0, // 32-byte ShardStateHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte ShardState
|
|
|
|
|
// END Header
|
|
|
|
|
// BEGIN 0-byte Txs
|
|
|
|
|
0xc0, |
|
|
|
|
// END Txs
|
|
|
|
|
// BEGIN 0-byte Uncles
|
|
|
|
|
0xc0, |
|
|
|
|
// END Uncles
|
|
|
|
|
// END extblock
|
|
|
|
|
}), 0)}, |
|
|
|
|
false, |
|
|
|
|
reflect.TypeOf(v0.NewHeader()), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"v1", |
|
|
|
|
args{s: rlp.NewStream(bytes.NewBuffer([]byte{ |
|
|
|
|
// BEGIN 689-byte tagged RLP envelope
|
|
|
|
|
0xf9, 0x02, 0xb1, |
|
|
|
|
0x87, // 7-byte tagged RLP signature
|
|
|
|
|
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
|
|
|
|
0x82, // 2-byte v1 header tag
|
|
|
|
|
'v', '1', |
|
|
|
|
// BEGIN 675-byte extblockV1
|
|
|
|
|
0xf9, 0x02, 0xa3, |
|
|
|
|
// BEGIN 669-byte tagged RLP envelope
|
|
|
|
|
0xf9, 0x02, 0x9d, |
|
|
|
|
0x87, // 7-byte tagged RLP signature
|
|
|
|
|
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
|
|
|
|
0x82, // 2-byte v1 header tag
|
|
|
|
|
'v', '1', |
|
|
|
|
// BEGIN 655-byte Header
|
|
|
|
|
0xf9, 0x02, 0x8f, |
|
|
|
|
0xa0, // 32-byte ParentHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x94, // 20-byte Coinbase
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte Root
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte TxHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte ReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte OutgoingReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte IncomingReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xb9, 0x01, 0x00, // 256-byte Bloom
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte Number
|
|
|
|
|
0x80, // 0-byte GasLimit
|
|
|
|
|
0x80, // 0-byte GasUsed
|
|
|
|
|
0x80, // 0-byte Time
|
|
|
|
|
0x80, // 0-byte Extra
|
|
|
|
|
0xa0, // 32-byte MixDigest
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte ViewID
|
|
|
|
|
0x80, // 0-byte Epoch
|
|
|
|
|
0x80, // 0-byte ShardID
|
|
|
|
|
0xb8, 0x60, // 96-byte LastCommitSignature
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte LastCommitBitmap
|
|
|
|
|
0xa0, // 32-byte ShardStateHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte Vrf
|
|
|
|
|
0x80, // 0-byte Vdf
|
|
|
|
|
0x80, // 0-byte ShardState
|
|
|
|
|
0x80, // 0-byte CrossLinks
|
|
|
|
|
// END Header
|
|
|
|
|
// END tagged RLP envelope
|
|
|
|
|
// BEGIN 0-byte Txs
|
|
|
|
|
0xc0, |
|
|
|
|
// END Txs
|
|
|
|
|
// BEGIN 0-byte Uncles
|
|
|
|
|
0xc0, |
|
|
|
|
// END Uncles
|
|
|
|
|
// BEGIN 0-byte IncomingReceipts
|
|
|
|
|
0xc0, |
|
|
|
|
// END IncomingReceipts
|
|
|
|
|
// END extblockV1
|
|
|
|
|
// END tagged RLP envelope
|
|
|
|
|
}), 0)}, |
|
|
|
|
false, |
|
|
|
|
reflect.TypeOf(v1.NewHeader()), |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
b := &Block{} |
|
|
|
|
err := b.DecodeRLP(tt.args.s) |
|
|
|
|
if (err != nil) != tt.wantErr { |
|
|
|
|
t.Errorf("DecodeRLP() error = %v, wantErr %v", err, tt.wantErr) |
|
|
|
|
} |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
gotHeaderType := reflect.TypeOf(b.header.Header) |
|
|
|
|
if gotHeaderType != tt.wantHeaderType { |
|
|
|
|
t.Errorf("DecodeRLP() got header type %s, want %s", |
|
|
|
|
taggedrlp.TypeName(gotHeaderType), |
|
|
|
|
taggedrlp.TypeName(tt.wantHeaderType)) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestBlock_EncodeRLP(t *testing.T) { |
|
|
|
|
tests := []struct { |
|
|
|
|
name string |
|
|
|
|
header blockif.Header |
|
|
|
|
wantBytes []byte |
|
|
|
|
wantErr bool |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
"v0", |
|
|
|
|
&v0.Header{}, |
|
|
|
|
[]byte{ |
|
|
|
|
// BEGIN 591-byte extblock
|
|
|
|
|
0xf9, 0x02, 0x4f, |
|
|
|
|
// BEGIN 586-byte Header
|
|
|
|
|
0xf9, 0x02, 0x4a, |
|
|
|
|
0xa0, // 32-byte ParentHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x94, // 20-byte Coinbase
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte Root
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte TxHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte ReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xb9, 0x01, 0x00, // 256-byte Bloom
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte Number
|
|
|
|
|
0x80, // 0-byte GasLimit
|
|
|
|
|
0x80, // 0-byte GasUsed
|
|
|
|
|
0x80, // 0-byte Time
|
|
|
|
|
0x80, // 0-byte Extra
|
|
|
|
|
0xa0, // 32-byte MixDigest
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte ViewID
|
|
|
|
|
0x80, // 0-byte Epoch
|
|
|
|
|
0x80, // 0-byte ShardID
|
|
|
|
|
0xb8, 0x60, // 96-byte LastCommitSignature
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte LastCommitBitmap
|
|
|
|
|
0xa0, // 32-byte ShardStateHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte ShardState
|
|
|
|
|
// END Header
|
|
|
|
|
// BEGIN 0-byte Txs
|
|
|
|
|
0xc0, |
|
|
|
|
// END Txs
|
|
|
|
|
// BEGIN 0-byte Uncles
|
|
|
|
|
0xc0, |
|
|
|
|
// END Uncles
|
|
|
|
|
// END extblock
|
|
|
|
|
}, |
|
|
|
|
false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"v1", |
|
|
|
|
&v1.Header{}, |
|
|
|
|
[]byte{ |
|
|
|
|
// BEGIN 689-byte tagged RLP envelope
|
|
|
|
|
0xf9, 0x02, 0xb1, |
|
|
|
|
0x87, // 7-byte tagged RLP signature
|
|
|
|
|
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
|
|
|
|
0x82, // 2-byte v1 header tag
|
|
|
|
|
'v', '1', |
|
|
|
|
// BEGIN 675-byte extblockV1
|
|
|
|
|
0xf9, 0x02, 0xa3, |
|
|
|
|
// BEGIN 669-byte tagged RLP envelope
|
|
|
|
|
0xf9, 0x02, 0x9d, |
|
|
|
|
0x87, // 7-byte tagged RLP signature
|
|
|
|
|
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
|
|
|
|
0x82, // 2-byte v1 header tag
|
|
|
|
|
'v', '1', |
|
|
|
|
// BEGIN 655-byte Header
|
|
|
|
|
0xf9, 0x02, 0x8f, |
|
|
|
|
0xa0, // 32-byte ParentHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x94, // 20-byte Coinbase
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte Root
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte TxHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte ReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte OutgoingReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xa0, // 32-byte IncomingReceiptHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0xb9, 0x01, 0x00, // 256-byte Bloom
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte Number
|
|
|
|
|
0x80, // 0-byte GasLimit
|
|
|
|
|
0x80, // 0-byte GasUsed
|
|
|
|
|
0x80, // 0-byte Time
|
|
|
|
|
0x80, // 0-byte Extra
|
|
|
|
|
0xa0, // 32-byte MixDigest
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte ViewID
|
|
|
|
|
0x80, // 0-byte Epoch
|
|
|
|
|
0x80, // 0-byte ShardID
|
|
|
|
|
0xb8, 0x60, // 96-byte LastCommitSignature
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte LastCommitBitmap
|
|
|
|
|
0xa0, // 32-byte ShardStateHash
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
|
0x80, // 0-byte Vrf
|
|
|
|
|
0x80, // 0-byte Vdf
|
|
|
|
|
0x80, // 0-byte ShardState
|
|
|
|
|
0x80, // 0-byte CrossLinks
|
|
|
|
|
// END Header
|
|
|
|
|
// END tagged RLP envelope
|
|
|
|
|
// BEGIN 0-byte Txs
|
|
|
|
|
0xc0, |
|
|
|
|
// END Txs
|
|
|
|
|
// BEGIN 0-byte Uncles
|
|
|
|
|
0xc0, |
|
|
|
|
// END Uncles
|
|
|
|
|
// BEGIN 0-byte IncomingReceipts
|
|
|
|
|
0xc0, |
|
|
|
|
// END IncomingReceipts
|
|
|
|
|
// END extblockV1
|
|
|
|
|
// END tagged RLP envelope
|
|
|
|
|
}, |
|
|
|
|
false, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
b := &Block{header: &block.Header{tt.header}} |
|
|
|
|
w := &bytes.Buffer{} |
|
|
|
|
err := b.EncodeRLP(w) |
|
|
|
|
if (err != nil) != tt.wantErr { |
|
|
|
|
t.Errorf("EncodeRLP() error = %v, wantErr %v", err, tt.wantErr) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if gotBytes := w.Bytes(); bytes.Compare(gotBytes, tt.wantBytes) != 0 { |
|
|
|
|
t.Errorf("EncodeRLP() got %x", gotBytes) |
|
|
|
|
t.Errorf("EncodeRLP() want %x", tt.wantBytes) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestBody_EncodeRLP(t *testing.T) { |
|
|
|
|
tests := []struct { |
|
|
|
|
name string |
|
|
|
|
bodyImpl BodyInterface |
|
|
|
|
wantBytes []byte |
|
|
|
|
wantErr bool |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
"v0", |
|
|
|
|
&BodyV0{}, |
|
|
|
|
[]byte{ |
|
|
|
|
0xc2, // BEGIN 2-byte BodyV0 struct
|
|
|
|
|
0xc0, // BEGIN 0-byte Transactions slice
|
|
|
|
|
// END Transactions slice
|
|
|
|
|
0xc0, // BEGIN 0-byte Uncles slice
|
|
|
|
|
// END Uncles slice
|
|
|
|
|
// END BodyV0 struct
|
|
|
|
|
}, |
|
|
|
|
false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"v1", |
|
|
|
|
&BodyV1{}, |
|
|
|
|
[]byte{ |
|
|
|
|
0xcf, // BEGIN 15-byte tagged RLP envelope
|
|
|
|
|
0x87, // BEGIN 7-byte tagged RLP signature
|
|
|
|
|
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
|
|
|
|
0x82, // BEGIN 2-byte type tag
|
|
|
|
|
'v', '1', |
|
|
|
|
0xc3, // BEGIN 3-byte BodyV1 struct
|
|
|
|
|
0xc0, // BEGIN 0-byte Transactions slice
|
|
|
|
|
// END Transactions slice
|
|
|
|
|
0xc0, // BEGIN 0-byte Uncles slice
|
|
|
|
|
// END Uncles slice
|
|
|
|
|
0xc0, // BEGIN 0-byte IncomingReceipts slice
|
|
|
|
|
// END IncomingReceipts slice
|
|
|
|
|
// END BodyV1 struct
|
|
|
|
|
// END tagged RLP envelope
|
|
|
|
|
}, |
|
|
|
|
false, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
b := &Body{BodyInterface: tt.bodyImpl} |
|
|
|
|
w := &bytes.Buffer{} |
|
|
|
|
err := b.EncodeRLP(w) |
|
|
|
|
if (err != nil) != tt.wantErr { |
|
|
|
|
t.Errorf("EncodeRLP() error = %v, wantErr %v", err, tt.wantErr) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if haveBytes := w.Bytes(); bytes.Compare(haveBytes, tt.wantBytes) != 0 { |
|
|
|
|
t.Errorf("EncodeRLP() have %x", haveBytes) |
|
|
|
|
t.Errorf("EncodeRLP() want %x", tt.wantBytes) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestBody_DecodeRLP(t *testing.T) { |
|
|
|
|
type args struct { |
|
|
|
|
s *rlp.Stream |
|
|
|
|
} |
|
|
|
|
tests := []struct { |
|
|
|
|
name string |
|
|
|
|
args args |
|
|
|
|
wantErr bool |
|
|
|
|
wantBodyType reflect.Type |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
"v0", |
|
|
|
|
args{rlp.NewStream(bytes.NewBuffer([]byte{ |
|
|
|
|
0xc2, // BEGIN 2-byte BodyV0 struct
|
|
|
|
|
0xc0, // BEGIN 0-byte Transactions slice
|
|
|
|
|
// END Transactions slice
|
|
|
|
|
0xc0, // BEGIN 0-byte Uncles slice
|
|
|
|
|
// END Uncles slice
|
|
|
|
|
// END BodyV0 struct
|
|
|
|
|
}), 0)}, |
|
|
|
|
false, |
|
|
|
|
reflect.TypeOf(&BodyV0{}), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"v1", |
|
|
|
|
args{rlp.NewStream(bytes.NewBuffer([]byte{ |
|
|
|
|
0xcf, // BEGIN 15-byte tagged RLP envelope
|
|
|
|
|
0x87, // BEGIN 7-byte tagged RLP signature
|
|
|
|
|
'H', 'm', 'n', 'y', 'T', 'g', 'd', |
|
|
|
|
0x82, // BEGIN 2-byte type tag
|
|
|
|
|
'v', '1', |
|
|
|
|
0xc3, // BEGIN 3-byte BodyV1 struct
|
|
|
|
|
0xc0, // BEGIN 0-byte Transactions slice
|
|
|
|
|
// END Transactions slice
|
|
|
|
|
0xc0, // BEGIN 0-byte Uncles slice
|
|
|
|
|
// END Uncles slice
|
|
|
|
|
0xc0, // BEGIN 0-byte IncomingReceipts slice
|
|
|
|
|
// END IncomingReceipts slice
|
|
|
|
|
// END BodyV1 struct
|
|
|
|
|
// END tagged RLP envelope
|
|
|
|
|
}), 0)}, |
|
|
|
|
false, |
|
|
|
|
reflect.TypeOf(&BodyV1{}), |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for _, tt := range tests { |
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
b := &Body{} |
|
|
|
|
err := b.DecodeRLP(tt.args.s) |
|
|
|
|
if (err != nil) != tt.wantErr { |
|
|
|
|
t.Errorf("DecodeRLP() error = %v, wantErr %v", err, tt.wantErr) |
|
|
|
|
} |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
haveBodyType := reflect.TypeOf(b.BodyInterface) |
|
|
|
|
if haveBodyType != tt.wantBodyType { |
|
|
|
|
t.Errorf("DecodeRLP() got body type %s, want %s", |
|
|
|
|
taggedrlp.TypeName(haveBodyType), |
|
|
|
|
taggedrlp.TypeName(tt.wantBodyType)) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|