-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
145 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,80 @@ | ||
package sharding | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
// TODO: this test needs to change as we will be serializing tx's into blobs | ||
// within the collation body instead. | ||
|
||
func TestCollation_AddTransactions(t *testing.T) { | ||
tests := []struct { | ||
transactions []*types.Transaction | ||
}{ | ||
{ | ||
transactions: []*types.Transaction{ | ||
makeTxWithGasLimit(0), | ||
makeTxWithGasLimit(1), | ||
makeTxWithGasLimit(2), | ||
makeTxWithGasLimit(3), | ||
}, | ||
}, { | ||
transactions: []*types.Transaction{}, | ||
}, | ||
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), | ||
} | ||
|
||
for _, tt := range tests { | ||
c := &Collation{} | ||
for _, tx := range tt.transactions { | ||
c.AddTransaction(tx) | ||
} | ||
results := c.Transactions() | ||
if len(results) != len(tt.transactions) { | ||
t.Fatalf("Wrong number of transactions. want=%d. got=%d", len(tt.transactions), len(results)) | ||
} | ||
for i, tx := range tt.transactions { | ||
if results[i] != tx { | ||
t.Fatalf("Mismatched transactions. wanted=%+v. got=%+v", tt.transactions, results) | ||
} | ||
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 TestCollation_ProposerAddress(t *testing.T) { | ||
proposerAddr := common.StringToAddress("proposer") | ||
header := NewCollationHeader(big.NewInt(1), nil, big.NewInt(1), &proposerAddr, []byte{}) | ||
body := []byte{} | ||
|
||
collation := NewCollation(header, body, nil) | ||
|
||
if collation.ProposerAddress().String() != proposerAddr.String() { | ||
t.Errorf("initialized collation does not contain correct proposer address") | ||
} | ||
} | ||
|
||
// TODO: this test needs to change as we will be serializing tx's into blobs | ||
// within the collation body instead. | ||
|
||
// func TestCollation_AddTransactions(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 := c.Transactions() | ||
// if len(results) != len(tt.transactions) { | ||
// t.Fatalf("Wrong number of transactions. want=%d. got=%d", len(tt.transactions), len(results)) | ||
// } | ||
// for i, tx := range tt.transactions { | ||
// if results[i] != tx { | ||
// t.Fatalf("Mismatched transactions. wanted=%+v. got=%+v", tt.transactions, results) | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
func makeTxWithGasLimit(gl uint64) *types.Transaction { | ||
return types.NewTransaction(0 /*nonce*/, common.HexToAddress("0x0") /*to*/, nil /*amount*/, gl, nil /*gasPrice*/, nil /*data*/) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters