Skip to content

Commit

Permalink
Stop skipping tests
Browse files Browse the repository at this point in the history
Right now the only tests being skipped is the p2p tests

Co-authored-by: kirugan <kirill@nethermind.io>
  • Loading branch information
derrix060 and kirugan committed Aug 9, 2024
1 parent 3cf58a1 commit 07a49b3
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 104 deletions.
10 changes: 5 additions & 5 deletions rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,13 @@ func TestBlockWithReceipts(t *testing.T) {
mainnetGw := adaptfeeder.New(client)

t.Run("pending block", func(t *testing.T) {
t.Skip()
block0, err := mainnetGw.BlockByNumber(context.Background(), 0)
require.NoError(t, err)

blockID := rpc.BlockID{Pending: true}

mockReader.EXPECT().Pending().Return(blockchain.Pending{Block: block0}, nil)
mockReader.EXPECT().L1Head().Return(&core.L1Head{}, nil)

resp, rpcErr := handler.BlockWithReceipts(blockID)
resp, rpcErr := handler.BlockWithReceipts(rpc.BlockID{Pending: true})
header := resp.BlockHeader

var txsWithReceipt []rpc.TransactionWithReceipt
Expand All @@ -622,14 +619,15 @@ func TestBlockWithReceipts(t *testing.T) {
Timestamp: header.Timestamp,
SequencerAddress: header.SequencerAddress,
L1GasPrice: header.L1GasPrice,
L1DataGasPrice: header.L1DataGasPrice,
L1DAMode: header.L1DAMode,
StarknetVersion: header.StarknetVersion,
},
Transactions: txsWithReceipt,
}, resp)
})

t.Run("accepted L1 block", func(t *testing.T) {
t.Skip()
block1, err := mainnetGw.BlockByNumber(context.Background(), 1)
require.NoError(t, err)

Expand Down Expand Up @@ -664,7 +662,9 @@ func TestBlockWithReceipts(t *testing.T) {
NewRoot: header.NewRoot,
Timestamp: header.Timestamp,
SequencerAddress: header.SequencerAddress,
L1DAMode: header.L1DAMode,
L1GasPrice: header.L1GasPrice,
L1DataGasPrice: header.L1DataGasPrice,
StarknetVersion: header.StarknetVersion,
},
Transactions: transactions,
Expand Down
45 changes: 21 additions & 24 deletions rpc/estimate_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpc_test
import (
"encoding/json"
"errors"
"fmt"
"testing"

"github.com/NethermindEth/juno/core"
Expand All @@ -18,8 +19,7 @@ import (
"go.uber.org/mock/gomock"
)

func TestEstimateMessageFee(t *testing.T) {
t.Skip()
func TestEstimateMessageFeeV0_6(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

Expand Down Expand Up @@ -57,7 +57,7 @@ func TestEstimateMessageFee(t *testing.T) {
Header: latestHeader,
}, gomock.Any(), &utils.Mainnet, gomock.Any(), false, true, false).DoAndReturn(
func(txns []core.Transaction, declaredClasses []core.Class, paidFeesOnL1 []*felt.Felt, blockInfo *vm.BlockInfo,
state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert bool,
state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert, useBlobData bool,
) ([]*felt.Felt, []*felt.Felt, []vm.TransactionTrace, error) {
require.Len(t, txns, 1)
assert.NotNil(t, txns[0].(*core.L1HandlerTransaction))
Expand All @@ -81,18 +81,21 @@ func TestEstimateMessageFee(t *testing.T) {

estimateFee, err := handler.EstimateMessageFeeV0_6(msg, rpc.BlockID{Latest: true})
require.Nil(t, err)
feeUnit := rpc.WEI
require.Equal(t, rpc.FeeEstimate{
GasConsumed: expectedGasConsumed,
GasPrice: latestHeader.GasPrice,
OverallFee: new(felt.Felt).Mul(expectedGasConsumed, latestHeader.GasPrice),
Unit: &feeUnit,
}, *estimateFee)
expectedJSON := fmt.Sprintf(
`{"gas_consumed":%q,"gas_price":%q,"overall_fee":%q,"unit":"WEI"}`,
expectedGasConsumed,
latestHeader.GasPrice,
new(felt.Felt).Mul(expectedGasConsumed, latestHeader.GasPrice),
)

// we check json response here because some fields are private and we can't set them and assert.Equal fails
// also in 0.6 response some fields should not be presented
estimateFeeJSON, jsonErr := json.Marshal(estimateFee)
require.NoError(t, jsonErr)
require.Equal(t, expectedJSON, string(estimateFeeJSON))
}

func TestEstimateFee(t *testing.T) {
t.Skip()

mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

Expand All @@ -110,24 +113,24 @@ func TestEstimateFee(t *testing.T) {

blockInfo := vm.BlockInfo{Header: &core.Header{}}
t.Run("ok with zero values", func(t *testing.T) {
mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, true, false, false).
Return([]*felt.Felt{}, []vm.TransactionTrace{}, nil)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, false, true, true).
Return([]*felt.Felt{}, []*felt.Felt{}, []vm.TransactionTrace{}, nil)

_, err := handler.EstimateFee([]rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{}, rpc.BlockID{Latest: true})
require.Nil(t, err)
})

t.Run("ok with zero values, skip validate", func(t *testing.T) {
mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, true, false, false).
Return([]*felt.Felt{}, []vm.TransactionTrace{}, nil)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, true, true, true).
Return([]*felt.Felt{}, []*felt.Felt{}, []vm.TransactionTrace{}, nil)

_, err := handler.EstimateFee([]rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag}, rpc.BlockID{Latest: true})
require.Nil(t, err)
})

t.Run("transaction execution error", func(t *testing.T) {
mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, true, false, false).
Return(nil, nil, vm.TransactionExecutionError{
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, true, true, true).
Return(nil, nil, nil, vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})
Expand All @@ -137,12 +140,6 @@ func TestEstimateFee(t *testing.T) {
TransactionIndex: 44,
ExecutionError: "oops",
}), err)

mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &blockInfo, mockState, n, false, true, true, false).
Return(nil, nil, vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})
})
}

Expand Down
6 changes: 2 additions & 4 deletions rpc/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ func (fc *fakeConn) Equal(other jsonrpc.Conn) bool {
}

func TestSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
t.Skip()
t.Parallel()
log := utils.NewNopZapLogger()
n := utils.Ptr(utils.Mainnet)
Expand Down Expand Up @@ -281,7 +280,7 @@ func TestSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
syncCancel()

// Receive a block header.
want := `{"jsonrpc":"2.0","method":"juno_subscribeNewHeads","params":{"result":{"block_hash":"0x4e1f77f39545afe866ac151ac908bd1a347a2a8a7d58bef1276db4f06fdf2f6","parent_hash":"0x2a70fb03fe363a2d6be843343a1d81ce6abeda1e9bd5cc6ad8fa9f45e30fdeb","block_number":2,"new_root":"0x3ceee867d50b5926bb88c0ec7e0b9c20ae6b537e74aac44b8fcf6bb6da138d9","timestamp":1637084470,"sequencer_address":"0x0","l1_gas_price":{"price_in_fri":"0x0","price_in_wei":"0x0"},"starknet_version":""},"subscription":%d}}`
want := `{"jsonrpc":"2.0","method":"juno_subscribeNewHeads","params":{"result":{"block_hash":"0x4e1f77f39545afe866ac151ac908bd1a347a2a8a7d58bef1276db4f06fdf2f6","parent_hash":"0x2a70fb03fe363a2d6be843343a1d81ce6abeda1e9bd5cc6ad8fa9f45e30fdeb","block_number":2,"new_root":"0x3ceee867d50b5926bb88c0ec7e0b9c20ae6b537e74aac44b8fcf6bb6da138d9","timestamp":1637084470,"sequencer_address":"0x0","l1_gas_price":{"price_in_fri":"0x0","price_in_wei":"0x0"},"l1_data_gas_price":{"price_in_fri":"0x0","price_in_wei":"0x0"},"l1_da_mode":"CALLDATA","starknet_version":""},"subscription":%d}}`
want = fmt.Sprintf(want, id)
got := make([]byte, len(want))
_, err := clientConn.Read(got)
Expand Down Expand Up @@ -312,7 +311,6 @@ func TestSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
}

func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
t.Skip()
t.Parallel()
log := utils.NewNopZapLogger()
n := utils.Ptr(utils.Mainnet)
Expand Down Expand Up @@ -382,7 +380,7 @@ func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
syncCancel()

// Receive a block header.
want = `{"jsonrpc":"2.0","method":"juno_subscribeNewHeads","params":{"result":{"block_hash":"0x4e1f77f39545afe866ac151ac908bd1a347a2a8a7d58bef1276db4f06fdf2f6","parent_hash":"0x2a70fb03fe363a2d6be843343a1d81ce6abeda1e9bd5cc6ad8fa9f45e30fdeb","block_number":2,"new_root":"0x3ceee867d50b5926bb88c0ec7e0b9c20ae6b537e74aac44b8fcf6bb6da138d9","timestamp":1637084470,"sequencer_address":"0x0","l1_gas_price":{"price_in_fri":"0x0","price_in_wei":"0x0"},"starknet_version":""},"subscription":%d}}`
want = `{"jsonrpc":"2.0","method":"juno_subscribeNewHeads","params":{"result":{"block_hash":"0x4e1f77f39545afe866ac151ac908bd1a347a2a8a7d58bef1276db4f06fdf2f6","parent_hash":"0x2a70fb03fe363a2d6be843343a1d81ce6abeda1e9bd5cc6ad8fa9f45e30fdeb","block_number":2,"new_root":"0x3ceee867d50b5926bb88c0ec7e0b9c20ae6b537e74aac44b8fcf6bb6da138d9","timestamp":1637084470,"sequencer_address":"0x0","l1_gas_price":{"price_in_fri":"0x0","price_in_wei":"0x0"},"l1_data_gas_price":{"price_in_fri":"0x0","price_in_wei":"0x0"},"l1_da_mode":"CALLDATA","starknet_version":""},"subscription":%d}}`
firstWant = fmt.Sprintf(want, firstID)
_, firstGot, err = conn1.Read(ctx)
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion rpc/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func (h *Handler) SimulateTransactions(id BlockID, transactions []BroadcastedTra
func (h *Handler) SimulateTransactionsV0_6(id BlockID, transactions []BroadcastedTransaction,
simulationFlags []SimulationFlag,
) ([]SimulatedTransaction, *jsonrpc.Error) {
return h.simulateTransactions(id, transactions, simulationFlags, true, true)
// todo double check errOnRevert = false
return h.simulateTransactions(id, transactions, simulationFlags, true, false)
}

//nolint:funlen,gocyclo
Expand Down
70 changes: 37 additions & 33 deletions rpc/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"go.uber.org/mock/gomock"
)

func TestSimulateTransactions(t *testing.T) {
t.Skip()
//nolint:dupl
func TestSimulateTransactionsV0_6(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

Expand All @@ -34,51 +34,55 @@ func TestSimulateTransactions(t *testing.T) {
mockReader.EXPECT().HeadsHeader().Return(headsHeader, nil).AnyTimes()

t.Run("ok with zero values, skip fee", func(t *testing.T) {
mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &vm.BlockInfo{
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, true, false, false, false).
Return([]*felt.Felt{}, []vm.TransactionTrace{}, nil)
Return([]*felt.Felt{}, []*felt.Felt{}, []vm.TransactionTrace{}, nil)

_, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipFeeChargeFlag})
_, err := handler.SimulateTransactionsV0_6(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipFeeChargeFlag})
require.Nil(t, err)
})

t.Run("ok with zero values, skip validate", func(t *testing.T) {
mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &vm.BlockInfo{
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, false, false, false, false).
Return([]*felt.Felt{}, []vm.TransactionTrace{}, nil)
}, mockState, n, false, true, false, false).
Return([]*felt.Felt{}, []*felt.Felt{}, []vm.TransactionTrace{}, nil)

_, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
_, err := handler.SimulateTransactionsV0_6(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
require.Nil(t, err)
})

t.Run("transaction execution error", func(t *testing.T) {
mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, false, false, false, false).
Return(nil, nil, vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})

_, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
require.Equal(t, rpc.ErrTransactionExecutionError.CloneWithData(rpc.TransactionExecutionErrorData{
TransactionIndex: 44,
ExecutionError: "oops",
}), err)
t.Run("v0_6", func(t *testing.T) { //nolint:dupl
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, false, true, false, false).
Return(nil, nil, nil, vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})

mockVM.EXPECT().Execute(nil, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, false, true, true, false).
Return(nil, nil, vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})
_, err := handler.SimulateTransactionsV0_6(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
require.Equal(t, rpc.ErrTransactionExecutionError.CloneWithData(rpc.TransactionExecutionErrorData{
TransactionIndex: 44,
ExecutionError: "oops",
}), err)
})
t.Run("v0_7", func(t *testing.T) { //nolint:dupl
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, false, true, false, true).
Return(nil, nil, nil, vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})

_, err = handler.SimulateTransactionsV0_6(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
require.Equal(t, rpc.ErrContractError.CloneWithData(rpc.ContractErrorData{
RevertError: "oops",
}), err)
_, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
require.Equal(t, rpc.ErrTransactionExecutionError.CloneWithData(rpc.TransactionExecutionErrorData{
TransactionIndex: 44,
ExecutionError: "oops",
}), err)
})
})
}
12 changes: 5 additions & 7 deletions rpc/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ func TestTraceTransactionV0_6(t *testing.T) {
})
}

func TestTraceBlockTransactions(t *testing.T) {
t.Skip()

func TestTraceBlockTransactionsV0_6(t *testing.T) {
errTests := map[string]rpc.BlockID{
"latest": {Latest: true},
"pending": {Pending: true},
Expand Down Expand Up @@ -474,9 +472,9 @@ func TestTraceBlockTransactions(t *testing.T) {
require.NoError(t, json.Unmarshal(vmTraceJSON, &vmTrace))
mockVM.EXPECT().Execute(block.Transactions, []core.Class{declaredClass.Class}, paidL1Fees, &vm.BlockInfo{Header: header},
gomock.Any(), n, false, false, false, false).
Return(nil, []vm.TransactionTrace{vmTrace, vmTrace}, nil)
Return(nil, nil, []vm.TransactionTrace{vmTrace, vmTrace}, nil)

result, err := handler.TraceBlockTransactions(context.Background(), rpc.BlockID{Hash: blockHash})
result, err := handler.TraceBlockTransactionsV0_6(context.Background(), rpc.BlockID{Hash: blockHash})
require.Nil(t, err)
assert.Equal(t, &vm.TransactionTrace{
ValidateInvocation: &vm.FunctionInvocation{},
Expand Down Expand Up @@ -541,15 +539,15 @@ func TestTraceBlockTransactions(t *testing.T) {
require.NoError(t, json.Unmarshal(vmTraceJSON, &vmTrace))
mockVM.EXPECT().Execute([]core.Transaction{tx}, []core.Class{declaredClass.Class}, []*felt.Felt{}, &vm.BlockInfo{Header: header},
gomock.Any(), n, false, false, false, false).
Return(nil, []vm.TransactionTrace{vmTrace}, nil)
Return(nil, nil, []vm.TransactionTrace{vmTrace}, nil)

expectedResult := []rpc.TracedBlockTransaction{
{
TransactionHash: tx.Hash(),
TraceRoot: &vmTrace,
},
}
result, err := handler.TraceBlockTransactions(context.Background(), rpc.BlockID{Hash: blockHash})
result, err := handler.TraceBlockTransactionsV0_6(context.Background(), rpc.BlockID{Hash: blockHash})
require.Nil(t, err)
assert.Equal(t, expectedResult, result)
})
Expand Down
Loading

0 comments on commit 07a49b3

Please sign in to comment.