Skip to content

Commit a9b8f33

Browse files
committed
test: Add validation test for LimitSlice type
1 parent a762e6a commit a9b8f33

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

rpc/rpccore/limit_slice_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/NethermindEth/juno/core/felt"
1212
"github.com/NethermindEth/juno/rpc/rpccore"
1313
rpcv9 "github.com/NethermindEth/juno/rpc/v9"
14+
"github.com/NethermindEth/juno/validator"
1415
"github.com/stretchr/testify/require"
1516
)
1617

@@ -56,6 +57,24 @@ func TestLazySlice(t *testing.T) {
5657
nil,
5758
)
5859
})
60+
61+
// This test ensures that the validation logic works for the values inside the Data slice.
62+
t.Run("ValidateRequiredFields", func(t *testing.T) {
63+
type BroadcastedTxLimitSlice = rpccore.LimitSlice[
64+
rpcv9.BroadcastedTransaction,
65+
rpccore.SimulationLimit,
66+
]
67+
68+
withEmptyValues := BroadcastedTxLimitSlice{
69+
Data: make([]rpcv9.BroadcastedTransaction, 10),
70+
}
71+
72+
validate := validator.Validator()
73+
// The [rpcv9.BroadcastedTransaction] struct contains 'validate:...' json tags,
74+
// so it should fail here since we're not filling them with valid values.
75+
err := validate.Struct(withEmptyValues)
76+
require.Error(t, err, "Validation is not working for the values inside the Data slice")
77+
})
5978
}
6079

6180
func runTest[T any, L rpccore.Limit](

0 commit comments

Comments
 (0)