Skip to content

Commit

Permalink
Fix NewBlock panic
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Feb 1, 2024
1 parent 25f58d5 commit f4be6e0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,11 @@ func TestGetL2BlockByHash(t *testing.T) {
[]*ethTypes.Transaction{ethTypes.NewTransaction(1, common.Address{}, big.NewInt(1), 1, big.NewInt(1), []byte{})},
nil,
[]*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))},
&trie.StackTrie{},
trie.NewStackTrie(nil),
),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
block := ethTypes.NewBlock(ethTypes.CopyHeader(tc.ExpectedResult.Header()), tc.ExpectedResult.Transactions(), tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, &trie.StackTrie{})
block := ethTypes.NewBlock(ethTypes.CopyHeader(tc.ExpectedResult.Header()), tc.ExpectedResult.Transactions(), tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, trie.NewStackTrie(nil))

m.DbTx.
On("Commit", context.Background()).
Expand Down Expand Up @@ -1145,12 +1145,12 @@ func TestGetL2BlockByNumber(t *testing.T) {
[]*ethTypes.Transaction{ethTypes.NewTransaction(1, common.Address{}, big.NewInt(1), 1, big.NewInt(1), []byte{})},
nil,
[]*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))},
&trie.StackTrie{},
trie.NewStackTrie(nil),
),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
block := ethTypes.NewBlock(ethTypes.CopyHeader(tc.ExpectedResult.Header()), tc.ExpectedResult.Transactions(),
tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, &trie.StackTrie{})
tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, trie.NewStackTrie(nil))

m.DbTx.
On("Commit", context.Background()).
Expand Down Expand Up @@ -1183,7 +1183,7 @@ func TestGetL2BlockByNumber(t *testing.T) {
[]*ethTypes.Transaction{ethTypes.NewTransaction(1, common.Address{}, big.NewInt(1), 1, big.NewInt(1), []byte{})},
nil,
[]*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))},
&trie.StackTrie{},
trie.NewStackTrie(nil),
),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
Expand Down Expand Up @@ -1267,16 +1267,16 @@ func TestGetL2BlockByNumber(t *testing.T) {
{
Name: "get pending block successfully",
Number: big.NewInt(-1),
ExpectedResult: ethTypes.NewBlock(&ethTypes.Header{Number: big.NewInt(2)}, nil, nil, nil, &trie.StackTrie{}),
ExpectedResult: ethTypes.NewBlock(&ethTypes.Header{Number: big.NewInt(2)}, nil, nil, nil, trie.NewStackTrie(nil)),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
lastBlockHeader := ethTypes.CopyHeader(tc.ExpectedResult.Header())
lastBlockHeader.Number.Sub(lastBlockHeader.Number, big.NewInt(1))
lastBlock := ethTypes.NewBlock(lastBlockHeader, nil, nil, nil, &trie.StackTrie{})
lastBlock := ethTypes.NewBlock(lastBlockHeader, nil, nil, nil, trie.NewStackTrie(nil))

expectedResultHeader := ethTypes.CopyHeader(tc.ExpectedResult.Header())
expectedResultHeader.ParentHash = lastBlock.Hash()
tc.ExpectedResult = ethTypes.NewBlock(expectedResultHeader, nil, nil, nil, &trie.StackTrie{})
tc.ExpectedResult = ethTypes.NewBlock(expectedResultHeader, nil, nil, nil, trie.NewStackTrie(nil))

m.DbTx.
On("Commit", context.Background()).
Expand Down
16 changes: 8 additions & 8 deletions jsonrpc/endpoints_zkevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,11 +1230,11 @@ func TestGetL2FullBlockByHash(t *testing.T) {
[]*ethTypes.Transaction{ethTypes.NewTransaction(1, common.Address{}, big.NewInt(1), 1, big.NewInt(1), []byte{})},
nil,
[]*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))},
&trie.StackTrie{},
trie.NewStackTrie(nil),
),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
block := ethTypes.NewBlock(ethTypes.CopyHeader(tc.ExpectedResult.Header()), tc.ExpectedResult.Transactions(), tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, &trie.StackTrie{})
block := ethTypes.NewBlock(ethTypes.CopyHeader(tc.ExpectedResult.Header()), tc.ExpectedResult.Transactions(), tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, trie.NewStackTrie(nil))

m.DbTx.
On("Commit", context.Background()).
Expand Down Expand Up @@ -1337,12 +1337,12 @@ func TestGetL2FullBlockByNumber(t *testing.T) {
[]*ethTypes.Transaction{ethTypes.NewTransaction(1, common.Address{}, big.NewInt(1), 1, big.NewInt(1), []byte{})},
nil,
[]*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))},
&trie.StackTrie{},
trie.NewStackTrie(nil),
),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
block := ethTypes.NewBlock(ethTypes.CopyHeader(tc.ExpectedResult.Header()), tc.ExpectedResult.Transactions(),
tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, &trie.StackTrie{})
tc.ExpectedResult.Uncles(), []*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))}, trie.NewStackTrie(nil))

m.DbTx.
On("Commit", context.Background()).
Expand Down Expand Up @@ -1375,7 +1375,7 @@ func TestGetL2FullBlockByNumber(t *testing.T) {
[]*ethTypes.Transaction{ethTypes.NewTransaction(1, common.Address{}, big.NewInt(1), 1, big.NewInt(1), []byte{})},
nil,
[]*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))},
&trie.StackTrie{},
trie.NewStackTrie(nil),
),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
Expand Down Expand Up @@ -1461,16 +1461,16 @@ func TestGetL2FullBlockByNumber(t *testing.T) {
{
Name: "get pending block successfully",
Number: "pending",
ExpectedResult: ethTypes.NewBlock(&ethTypes.Header{Number: big.NewInt(2)}, nil, nil, nil, &trie.StackTrie{}),
ExpectedResult: ethTypes.NewBlock(&ethTypes.Header{Number: big.NewInt(2)}, nil, nil, nil, trie.NewStackTrie(nil)),
ExpectedError: nil,
SetupMocks: func(m *mocksWrapper, tc *testCase) {
lastBlockHeader := ethTypes.CopyHeader(tc.ExpectedResult.Header())
lastBlockHeader.Number.Sub(lastBlockHeader.Number, big.NewInt(1))
lastBlock := ethTypes.NewBlock(lastBlockHeader, nil, nil, nil, &trie.StackTrie{})
lastBlock := ethTypes.NewBlock(lastBlockHeader, nil, nil, nil, trie.NewStackTrie(nil))

expectedResultHeader := ethTypes.CopyHeader(tc.ExpectedResult.Header())
expectedResultHeader.ParentHash = lastBlock.Hash()
tc.ExpectedResult = ethTypes.NewBlock(expectedResultHeader, nil, nil, nil, &trie.StackTrie{})
tc.ExpectedResult = ethTypes.NewBlock(expectedResultHeader, nil, nil, nil, trie.NewStackTrie(nil))

m.DbTx.
On("Commit", context.Background()).
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestBatchRequests(t *testing.T) {
[]*ethTypes.Transaction{ethTypes.NewTransaction(1, common.Address{}, big.NewInt(1), 1, big.NewInt(1), []byte{})},
nil,
[]*ethTypes.Receipt{ethTypes.NewReceipt([]byte{}, false, uint64(0))},
&trie.StackTrie{},
trie.NewStackTrie(nil),
)

testCases := []testCase{
Expand Down
2 changes: 1 addition & 1 deletion state/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (s *State) SetGenesis(ctx context.Context, block Block, genesis Genesis, db
log.Info("Genesis root ", rootHex)

receipts := []*types.Receipt{}
l2Block := types.NewBlock(header, []*types.Transaction{}, []*types.Header{}, receipts, &trie.StackTrie{})
l2Block := types.NewBlock(header, []*types.Transaction{}, []*types.Header{}, receipts, trie.NewStackTrie(nil))
l2Block.ReceivedAt = block.ReceivedAt

storeTxsEGPData := []StoreTxEGPData{}
Expand Down
6 changes: 3 additions & 3 deletions state/pgstatestorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestGetBatchByL2BlockNumber(t *testing.T) {
receipts := []*types.Receipt{receipt}

// Create block to be able to calculate its hash
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, &trie.StackTrie{})
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, trie.NewStackTrie(nil))
receipt.BlockHash = l2Block.Hash()

storeTxsEGPData := []state.StoreTxEGPData{}
Expand Down Expand Up @@ -785,7 +785,7 @@ func TestGetLogs(t *testing.T) {
Time: uint64(time.Unix()),
}

l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, &trie.StackTrie{})
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, trie.NewStackTrie(nil))
for _, receipt := range receipts {
receipt.BlockHash = l2Block.Hash()
}
Expand Down Expand Up @@ -908,7 +908,7 @@ func TestGetNativeBlockHashesInRange(t *testing.T) {
Time: uint64(time.Unix()),
}

l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, &trie.StackTrie{})
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, trie.NewStackTrie(nil))
for _, receipt := range receipts {
receipt.BlockHash = l2Block.Hash()
}
Expand Down
4 changes: 2 additions & 2 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ func TestExecutorRevert(t *testing.T) {
transactions := []*types.Transaction{signedTx0, signedTx1}

// Create block to be able to calculate its hash
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, &trie.StackTrie{})
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, trie.NewStackTrie(nil))
l2Block.ReceivedAt = time.Now()

receipt.BlockHash = l2Block.Hash()
Expand Down Expand Up @@ -1733,7 +1733,7 @@ func TestAddGetL2Block(t *testing.T) {
receipts := []*types.Receipt{receipt}

// Create block to be able to calculate its hash
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, &trie.StackTrie{})
l2Block := types.NewBlock(header, transactions, []*types.Header{}, receipts, trie.NewStackTrie(nil))
l2Block.ReceivedAt = time

receipt.BlockHash = l2Block.Hash()
Expand Down
4 changes: 2 additions & 2 deletions state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *State) StoreTransactions(ctx context.Context, batchNumber uint64, proce
receipts := []*types.Receipt{receipt}

// Create block to be able to calculate its hash
block := types.NewBlock(header, transactions, []*types.Header{}, receipts, &trie.StackTrie{})
block := types.NewBlock(header, transactions, []*types.Header{}, receipts, trie.NewStackTrie(nil))
block.ReceivedAt = processingContext.Timestamp

receipt.BlockHash = block.Hash()
Expand Down Expand Up @@ -954,7 +954,7 @@ func (s *State) StoreTransaction(ctx context.Context, batchNumber uint64, proces
receipts := []*types.Receipt{receipt}

// Create block to be able to calculate its hash
block := types.NewBlock(header, transactions, []*types.Header{}, receipts, &trie.StackTrie{})
block := types.NewBlock(header, transactions, []*types.Header{}, receipts, trie.NewStackTrie(nil))
block.ReceivedAt = time.Unix(int64(timestamp), 0)

receipt.BlockHash = block.Hash()
Expand Down

0 comments on commit f4be6e0

Please sign in to comment.