mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
52cd2b04ed
Former-commit-id: 5901594a02b82d0cd11e85593f7021d0cb0a6d62 [formerly dd57899b147bfb258557c20917b971338bc79f84] Former-commit-id: 047157dcdaf452f1e9d329684dd632c4a44c8af6
64 lines
1.4 KiB
Go
64 lines
1.4 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")
|
|
}
|
|
}
|
|
}
|
|
|
|
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 ----%v---%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*/)
|
|
}
|