Skip to content

Commit

Permalink
Fixed tests in 'ride' package. Refactored a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeskov committed Jun 17, 2022
1 parent 692f2e8 commit 1031b74
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 201 deletions.
13 changes: 9 additions & 4 deletions pkg/ride/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ var (
errDeletedEntry = errors.New("entry has been deleted")
)

var (
libV2CheckMessageLength = func(int) bool { return true }
libV3CheckMessageLength = func(l int) bool {
return l <= maxMessageLength
}
)

type lastTwoInvokeComplexities [2]int

func (l *lastTwoInvokeComplexities) pushComplexity(complexity int) {
Expand Down Expand Up @@ -1107,7 +1114,7 @@ func NewEnvironment(scheme proto.Scheme, state types.SmartState, internalPayment
sch: scheme,
st: state,
h: rideInt(height),
check: func(int) bool { return true }, // By default, for versions below 2 there was no check, always ok.
check: libV2CheckMessageLength, // By default, for versions below 2 there was no check, always ok.
takeStr: func(s string, n int) rideString { panic("function 'takeStr' was not initialized") },
validatePaymentsAfter: internalPaymentsValidationHeight,
}, nil
Expand Down Expand Up @@ -1213,9 +1220,7 @@ func (e *EvaluationEnvironment) ChooseTakeString(isRideV5 bool) {
func (e *EvaluationEnvironment) ChooseSizeCheck(v ast.LibraryVersion) {
e.ver = v
if v > ast.LibV2 {
e.check = func(l int) bool {
return l <= maxMessageLength
}
e.check = libV3CheckMessageLength
}
}

Expand Down
19 changes: 10 additions & 9 deletions pkg/ride/functions_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import (
)

var (
v2check = func(int) bool {
return true
}
v3check = func(size int) bool {
return size <= maxMessageLength
}
trueFn = func() bool { return true }
falseFn = func() bool { return false }
)

var (
v2check = libV2CheckMessageLength
v3check = libV3CheckMessageLength
v5takeString = takeRideString
noRideV6 = func() bool {
return false
}
yesRideV5 = trueFn
yesRideV6 = trueFn
noRideV6 = falseFn
)

func TestAddressFromString(t *testing.T) {
Expand Down
Loading

0 comments on commit 1031b74

Please sign in to comment.