Add an interop test for block header serialisation

This commit is contained in:
Aayush Rajasekaran 2020-04-17 19:43:37 -04:00
parent 9a0d0511c7
commit 5220a61fc5

View File

@ -2,7 +2,9 @@ package types
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/filecoin-project/specs-actors/actors/abi"
"reflect"
"testing"
@ -63,6 +65,62 @@ func TestBlockHeaderSerialization(t *testing.T) {
}
}
func TestInteropBH(t *testing.T) {
newAddr, err := address.NewSecp256k1Address([]byte("address0"))
if err != nil {
t.Fatal(err)
}
mcid, err := cid.Parse("bafy2bzaceaxyj7xq27gc2747adjcirpxx52tt7owqx6z6kckun7tqivvoym4y")
if err != nil {
t.Fatal(err)
}
posts := []abi.PoStProof{
{abi.RegisteredProof_StackedDRG2KiBWinningPoSt, []byte{0x07}},
}
bh := &BlockHeader{
Miner: newAddr,
Ticket: &Ticket{[]byte{0x01, 0x02, 0x03}},
ElectionProof: &ElectionProof{[]byte{0x0a, 0x0b}},
BeaconEntries: []BeaconEntry{
{
Round: 5,
Data: []byte{0x0c},
//prevRound: 0,
},
},
Height: 2,
Messages: mcid,
ParentMessageReceipts: mcid,
Parents: []cid.Cid{mcid},
ParentWeight: NewInt(1000),
ForkSignaling: 3,
ParentStateRoot: mcid,
Timestamp: 1,
WinPoStProof: posts,
BlockSig: &crypto.Signature{
Type: crypto.SigTypeBLS,
Data: []byte{0x3},
},
BLSAggregate: &crypto.Signature{},
}
bhsb, err := bh.SigningBytes()
if err != nil {
t.Fatal(err)
}
// acquired from go-filecoin
gfc := "8f5501d04cb15021bf6bd003073d79e2238d4e61f1ad22814301020381420a0b818205410c818209410781d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc430003e802d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc410001f603"
if gfc != hex.EncodeToString(bhsb) {
t.Fatal("not equal!")
}
}
func BenchmarkBlockHeaderMarshal(b *testing.B) {
bh := testBlockHeader(b)