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 9f73108 commit 3a6b23e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,11 +986,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 @@ -1085,12 +1085,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 @@ -1123,7 +1123,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 @@ -1207,16 +1207,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 @@ -1336,12 +1336,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 @@ -1374,7 +1374,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 @@ -1460,16 +1460,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 state/pgstatestorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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()

err = pgStateStorage.AddL2Block(ctx, batchNumber, l2Block, receipts, state.MaxEffectivePercentage, dbTx)
Expand Down
4 changes: 2 additions & 2 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,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 @@ -1718,7 +1718,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

0 comments on commit 3a6b23e

Please sign in to comment.