From 039c2e3453b3422a92b10cf947402b28fbe4bc2f Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 3 May 2018 16:32:42 -0500 Subject: [PATCH] sharding: readded tx added test, travis passes Former-commit-id: 4bd71e699dfe2515c6b472fd41df1ab51b1cb017 [formerly d9475982b5f6ed7249fb2c4470b3a3889ccb430f] Former-commit-id: d6c56cc922a93cf33c22f7650061463c064583b9 --- sharding/collation_test.go | 64 ++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/sharding/collation_test.go b/sharding/collation_test.go index 72d726f77..d1d8daa67 100644 --- a/sharding/collation_test.go +++ b/sharding/collation_test.go @@ -1,6 +1,8 @@ package sharding import ( + "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" ) @@ -8,38 +10,38 @@ import ( // 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_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) -// } -// } -// } -// } + 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*/)