-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Computation parity with FVM #451
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,19 +157,82 @@ func TestInfiniteScript(t *testing.T) { | |
|
||
t.Parallel() | ||
|
||
const limit = 1000 | ||
const limit = 90 | ||
b, err := emulator.New( | ||
emulator.WithScriptGasLimit(limit), | ||
) | ||
require.NoError(t, err) | ||
|
||
const code = ` | ||
pub fun main() { | ||
main() | ||
} | ||
` | ||
pub fun main() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mixed tabs and spaces (here and in other cadence scripts) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 82b2bd6 |
||
main() | ||
} | ||
` | ||
result, err := b.ExecuteScript([]byte(code), nil) | ||
require.NoError(t, err) | ||
|
||
require.True(t, fvmerrors.IsComputationLimitExceededError(result.Error)) | ||
} | ||
|
||
func TestScriptWithExceeedingComputationLimit(t *testing.T) { | ||
|
||
t.Parallel() | ||
|
||
const limit = 2000 | ||
b, err := emulator.New( | ||
emulator.WithScriptGasLimit(limit), | ||
) | ||
require.NoError(t, err) | ||
|
||
const code = ` | ||
pub fun main() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe store the script in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I restructured the tests to remove the script duplication in 82b2bd6 |
||
var s: Int256 = 1024102410241024 | ||
var i: Int256 = 0 | ||
var a: Int256 = 7 | ||
var b: Int256 = 5 | ||
var c: Int256 = 2 | ||
|
||
while i < 150000 { | ||
s = s * a | ||
s = s / b | ||
s = s / c | ||
i = i + 1 | ||
} | ||
} | ||
` | ||
result, err := b.ExecuteScript([]byte(code), nil) | ||
require.NoError(t, err) | ||
|
||
require.True(t, fvmerrors.IsComputationLimitExceededError(result.Error)) | ||
} | ||
|
||
func TestScriptWithSufficientComputationLimit(t *testing.T) { | ||
|
||
t.Parallel() | ||
|
||
const limit = 19000 | ||
b, err := emulator.New( | ||
emulator.WithScriptGasLimit(limit), | ||
) | ||
require.NoError(t, err) | ||
|
||
const code = ` | ||
pub fun main() { | ||
var s: Int256 = 1024102410241024 | ||
var i: Int256 = 0 | ||
var a: Int256 = 7 | ||
var b: Int256 = 5 | ||
var c: Int256 = 2 | ||
|
||
while i < 150000 { | ||
s = s * a | ||
s = s / b | ||
s = s / c | ||
i = i + 1 | ||
} | ||
} | ||
` | ||
result, err := b.ExecuteScript([]byte(code), nil) | ||
require.NoError(t, err) | ||
require.NoError(t, result.Error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-Peter Could you please bring back the comment describing where these magic values come from, i.e. add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@turbolent Sure thing 😇