Skip to content

Commit

Permalink
test(logic): add test for validate and invalidate white/backlist files
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Apr 24, 2023
1 parent fec5745 commit 3ff413b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions x/logic/keeper/grpc_query_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func TestGRPCParams(t *testing.T) {
types.WithBootstrap("bootstrap"),
types.WithPredicatesBlacklist([]string{"halt/1"}),
types.WithPredicatesWhitelist([]string{"source_file/1"}),
types.WithVirtualFilesBlacklist([]string{"file1"}),
types.WithVirtualFilesWhitelist([]string{"file2"}),
),
types.NewLimits(
types.WithMaxGas(math.NewUint(1)),
Expand Down
28 changes: 25 additions & 3 deletions x/logic/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestValidateParams(t *testing.T) {
types.WithBootstrap("bootstrap"),
types.WithPredicatesBlacklist([]string{"halt/1"}),
types.WithPredicatesWhitelist([]string{"source_file/1"}),
types.WithVirtualFilesBlacklist([]string{"file1"}),
types.WithVirtualFilesWhitelist([]string{"file2"}),
),
types.NewLimits(
types.WithMaxGas(math.NewUint(1)),
Expand All @@ -41,26 +43,46 @@ func TestValidateParams(t *testing.T) {
expectErr: false,
err: nil,
},
{
name: "validate invalid virtual files blacklist params",
params: types.NewParams(
types.NewInterpreter(
types.WithVirtualFilesBlacklist([]string{"https://foo{bar/"}),
),
types.NewLimits(),
),
expectErr: true,
err: fmt.Errorf("invalid virtual file in blacklist: https://foo{bar/"),
},
{
name: "validate invalid virtual files whitelist params",
params: types.NewParams(
types.NewInterpreter(
types.WithVirtualFilesWhitelist([]string{"https://foo{bar/"}),
),
types.NewLimits(),
),
expectErr: true,
err: fmt.Errorf("invalid virtual file in whitelist: https://foo{bar/"),
},
}

for nc, tc := range cases {
Convey(
fmt.Sprintf("Given test case #%d: %v, with params: %v", nc, tc.name, tc.params), func() {

Convey("when validate params", func() {
err := tc.params.Validate()

if tc.expectErr {
Convey("then params validation expect error", func() {
So(err, ShouldNotBeNil)
So(err, ShouldEqual, tc.err)
So(err, ShouldResemble, tc.err)
})
} else {
Convey("then error should be nil", func() {
So(err, ShouldBeNil)
})
}

})
})
}
Expand Down

0 comments on commit 3ff413b

Please sign in to comment.