Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan committed Oct 22, 2024
1 parent 121965f commit c5ff28c
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 458 deletions.
16 changes: 8 additions & 8 deletions mocks/mock_vm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func TestBlockWithTxHashesV013(t *testing.T) {

mockReader.EXPECT().BlockByNumber(gomock.Any()).Return(coreBlock, nil)
mockReader.EXPECT().L1Head().Return(&core.L1Head{}, nil)
got, rpcErr := handler.BlockWithTxsV0_6(rpc.BlockID{Number: blockNumber})
got, rpcErr := handler.BlockWithTxs(rpc.BlockID{Number: blockNumber})
require.Nil(t, rpcErr)
got.Transactions = got.Transactions[:1]

Expand All @@ -512,10 +512,15 @@ func TestBlockWithTxHashesV013(t *testing.T) {
NewRoot: coreBlock.GlobalStateRoot,
Number: &coreBlock.Number,
ParentHash: coreBlock.ParentHash,
L1DAMode: utils.Ptr(rpc.Blob),
L1GasPrice: &rpc.ResourcePrice{
InFri: utils.HexToFelt(t, "0x17882b6aa74"),
InWei: utils.HexToFelt(t, "0x3b9aca10"),
},
L1DataGasPrice: &rpc.ResourcePrice{
InFri: utils.HexToFelt(t, "0x2cc6d7f596e1"),
InWei: utils.HexToFelt(t, "0x716a8f6dd"),
},
SequencerAddress: coreBlock.SequencerAddress,
Timestamp: coreBlock.Timestamp,
},
Expand Down
6 changes: 3 additions & 3 deletions rpc/estimate_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestEstimateFee(t *testing.T) {

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

_, httpHeader, err := handler.EstimateFee([]rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{}, rpc.BlockID{Latest: true})
Expand All @@ -43,7 +43,7 @@ func TestEstimateFee(t *testing.T) {
})

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

_, httpHeader, err := handler.EstimateFee([]rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag}, rpc.BlockID{Latest: true})
Expand All @@ -52,7 +52,7 @@ func TestEstimateFee(t *testing.T) {
})

t.Run("transaction execution error", func(t *testing.T) {
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, true, true, true).
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &blockInfo, mockState, n, true, true, true).
Return(nil, nil, nil, uint64(0), vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
Expand Down
4 changes: 3 additions & 1 deletion rpc/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func (h *Handler) SimulateTransactions(id BlockID, transactions []BroadcastedTra
}

//nolint:funlen,gocyclo
func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTransaction, simulationFlags []SimulationFlag, errOnRevert bool) ([]SimulatedTransaction, http.Header, *jsonrpc.Error) {
func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTransaction,
simulationFlags []SimulationFlag, errOnRevert bool,
) ([]SimulatedTransaction, http.Header, *jsonrpc.Error) {
skipFeeCharge := slices.Contains(simulationFlags, SkipFeeChargeFlag)
skipValidate := slices.Contains(simulationFlags, SkipValidateFlag)

Expand Down
30 changes: 7 additions & 23 deletions rpc/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

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

Expand All @@ -38,10 +38,10 @@ func TestSimulateTransactionsV0_6(t *testing.T) {
stepsUsed := uint64(123)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, true, false, false, false).
}, mockState, n, true, false, false).
Return([]*felt.Felt{}, []core.GasConsumed{}, []vm.TransactionTrace{}, stepsUsed, nil)

_, httpHeader, err := handler.SimulateTransactionsV0_6(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipFeeChargeFlag})
_, httpHeader, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipFeeChargeFlag})
require.Nil(t, err)
assert.Equal(t, httpHeader.Get(rpc.ExecutionStepsHeader), "123")
})
Expand All @@ -50,35 +50,19 @@ func TestSimulateTransactionsV0_6(t *testing.T) {
stepsUsed := uint64(123)
mockVM.EXPECT().Execute([]core.Transaction{}, nil, []*felt.Felt{}, &vm.BlockInfo{
Header: headsHeader,
}, mockState, n, false, true, false, false).
}, mockState, n, false, true, false).
Return([]*felt.Felt{}, []core.GasConsumed{}, []vm.TransactionTrace{}, stepsUsed, nil)

_, httpHeader, err := handler.SimulateTransactionsV0_6(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
_, httpHeader, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
require.Nil(t, err)
assert.Equal(t, httpHeader.Get(rpc.ExecutionStepsHeader), "123")
})

t.Run("transaction execution error", func(t *testing.T) {
t.Run("v0_6", func(t *testing.T) { //nolint:dupl
t.Run("v0_7, v0_8", 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, uint64(0), vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
})

_, httpHeader, 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)
require.Equal(t, httpHeader.Get(rpc.ExecutionStepsHeader), "0")
})
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).
}, mockState, n, false, true, false).
Return(nil, nil, nil, uint64(0), vm.TransactionExecutionError{
Index: 44,
Cause: errors.New("oops"),
Expand Down
1 change: 1 addition & 0 deletions rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (h *Handler) TraceBlockTransactions(ctx context.Context, id BlockID) ([]Tra
return h.traceBlockTransactions(ctx, block)
}

//nolint:funlen,gocyclo
func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block) ([]TracedBlockTransaction, http.Header, *jsonrpc.Error) {
httpHeader := http.Header{}
httpHeader.Set(ExecutionStepsHeader, "0")
Expand Down
182 changes: 26 additions & 156 deletions rpc/trace_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (h *Handler) TransactionByBlockIDAndIndex(id BlockID, txIndex int) (*Transa
//
// It follows the specification defined here:
// https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json#L222
func (h *Handler) TransactionReceiptByHash(hash felt.Felt) (*TransactionReceipt, *jsonrpc.Error) { //nolint:dupl
func (h *Handler) TransactionReceiptByHash(hash felt.Felt) (*TransactionReceipt, *jsonrpc.Error) {
txn, err := h.bcReader.TransactionByHash(&hash)
if err != nil {
return nil, ErrTxnHashNotFound
Expand Down
Loading

0 comments on commit c5ff28c

Please sign in to comment.