mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
be6051d800
Former-commit-id: 7f58a5eb03fa6347ff5fae94443bf896f9db0486 [formerly ba599c2e0344c9e416cc5fea735407f3df3624d9] Former-commit-id: 13abf7e8ce922cb3a81e43b03d1793af2c9d6557
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package sharding
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
)
|
|
|
|
func TestCollation_Transactions(t *testing.T) {
|
|
header := NewCollationHeader(big.NewInt(1), nil, big.NewInt(1), nil, []byte{})
|
|
body := []byte{}
|
|
transactions := []*types.Transaction{
|
|
makeTxWithGasLimit(0),
|
|
makeTxWithGasLimit(1),
|
|
makeTxWithGasLimit(2),
|
|
makeTxWithGasLimit(3),
|
|
}
|
|
|
|
collation := NewCollation(header, body, transactions)
|
|
|
|
for i, tx := range collation.Transactions() {
|
|
if tx.Hash().String() != transactions[i].Hash().String() {
|
|
t.Errorf("initialized collation struct does not contain correct transactions")
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO: Add test for converting *types.Transaction into raw blobs
|
|
|
|
//Tests thta Transactions can be serialised
|
|
func TestSerialize(t *testing.T) {
|
|
tests := []struct {
|
|
transactions []*types.Transaction
|
|
}{
|
|
{
|
|
transactions: []*types.Transaction{
|
|
makeTxWithGasLimit(0),
|
|
makeTxWithGasLimit(1),
|
|
makeTxWithGasLimit(2),
|
|
makeTxWithGasLimit(3),
|
|
},
|
|
}, {
|
|
transactions: []*types.Transaction{},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
c := &Collation{}
|
|
for _, tx := range tt.transactions {
|
|
c.AddTransaction(tx)
|
|
}
|
|
|
|
results, err := c.Serialize()
|
|
if err != nil {
|
|
t.Fatalf("%v\n %v\n %v", err, results, c.transactions)
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func makeTxWithGasLimit(gl uint64) *types.Transaction {
|
|
return types.NewTransaction(0 /*nonce*/, common.HexToAddress("0x0") /*to*/, nil /*amount*/, gl, nil /*gasPrice*/, nil /*data*/)
|
|
}
|