Skip to content
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

itest: fix FEVM tests for upstream changes #10193

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions itests/fevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func buildInputFromuint64(number uint64) []byte {
// recursive delegate calls that fail due to gas limits are currently getting to 229 iterations
// before running out of gas
func recursiveDelegatecallFail(ctx context.Context, t *testing.T, client *kit.TestFullNode, filename string, count uint64) {
expectedIterationsBeforeFailing := int(229)
expectedIterationsBeforeFailing := int(228)
fromAddr, idAddr := client.EVM().DeployContractFromFilename(ctx, filename)
t.Log("recursion count - ", count)
inputData := buildInputFromuint64(count)
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestFEVMRecursiveFail(t *testing.T) {
t.Run(fmt.Sprintf("TestFEVMRecursiveFail%d", failCallCount), func(t *testing.T) {
_, wait, err := client.EVM().InvokeContractByFuncName(ctx, fromAddr, idAddr, "recursiveCall(uint256)", buildInputFromuint64(failCallCount))
require.Error(t, err)
require.Equal(t, exitcode.ExitCode(23), wait.Receipt.ExitCode)
require.Equal(t, exitcode.ExitCode(37), wait.Receipt.ExitCode)
})
}
}
Expand All @@ -150,20 +150,20 @@ func TestFEVMRecursive2(t *testing.T) {
require.Equal(t, 2, len(events))
}

// TestFEVMBasic does a basic fevm contract installation and invocation
// recursive delegate call succeeds up to 238 times
// TestFEVMRecursiveDelegateCall tests the maximum delegatecall recursion depth. It currently
// succeeds succeeds up to 228 times.
func TestFEVMRecursiveDelegatecall(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't making a lot of sense to me:

  1. recursiveDelegatecallFail has always expected 228 successes, not 238.
  2. If I change the "failure" loop to start at 229, the calls succeed and the test fails. But if I change the success loop to end at 238, the success loop fails.

So there appears to be a gulf between success/failure. This is not good but I'm not sure what's going on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also nit that the comment on top of the test is wrong

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fixed)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 30 increment in the loop makes it hard to tell what the exact threshold is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magik6k @Stebalien thanks 100% agree - i reorganized the test #10195


ctx, cancel, client := kit.SetupFEVMTest(t)
defer cancel()

filename := "contracts/RecursiveDelegeatecall.hex"

//success with 238 or fewer calls
for i := uint64(1); i <= 238; i += 30 {
//success with 228 or fewer calls
for i := uint64(1); i <= 228; i += 30 {
recursiveDelegatecallSuccess(ctx, t, client, filename, i)
}
recursiveDelegatecallSuccess(ctx, t, client, filename, uint64(238))
recursiveDelegatecallSuccess(ctx, t, client, filename, uint64(228))

for i := uint64(239); i <= 800; i += 40 {
recursiveDelegatecallFail(ctx, t, client, filename, i)
Expand Down Expand Up @@ -470,10 +470,9 @@ func TestFEVMSendGasLimit(t *testing.T) {
}

// TestFEVMDelegateCall deploys the two contracts in TestFEVMDelegateCall but instead of A calling B, A calls A which should cause A to cause A in an infinite loop and should give a reasonable error
// XXX should not be fatal errors
func TestFEVMDelegateCallRecursiveFail(t *testing.T) {
//TODO change the gas limit of this invocation and confirm that the number of errors is different
//also TODO should we not have fatal error show up here?
//TODO change the gas limit of this invocation and confirm that the number of errors is
// different
ctx, cancel, client := kit.SetupFEVMTest(t)
defer cancel()

Expand All @@ -486,17 +485,16 @@ func TestFEVMDelegateCallRecursiveFail(t *testing.T) {
inputDataValue := inputDataFromArray([]byte{7})
inputData := append(inputDataContract, inputDataValue...)

//verify that the returned value of the call to setvars is 7
//verify that we run out of gas then revert.
_, wait, err := client.EVM().InvokeContractByFuncName(ctx, fromAddr, actorAddr, "setVarsSelf(address,uint256)", inputData)
require.Error(t, err)
require.Equal(t, exitcode.SysErrorIllegalArgument, wait.Receipt.ExitCode)
require.Equal(t, exitcode.ExitCode(33), wait.Receipt.ExitCode)

//assert no fatal errors but still there are errors::
errorAny := "fatal error"
require.NotContains(t, err.Error(), errorAny)
}

// XXX Currently fails as self destruct has a bug
// TestFEVMTestSendValueThroughContracts creates A and B contract and exchanges value
// and self destructs and accounts for value sent
func TestFEVMTestSendValueThroughContractsAndDestroy(t *testing.T) {
Expand Down