From 73102e9432f31cb68f2571d76cd59d9785470090 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 17 Feb 2023 13:29:53 -0800 Subject: [PATCH] test: eth: make sure we can deploy a new placeholder on transfer (#10281) We have a test that triggers smart-contract logic on "transfers", but nothing that tries to create a new actor as a side-effect of a transfer. fixes https://github.com/filecoin-project/ref-fvm/issues/1670 --- itests/fevm_test.go | 33 +++++++++++++++++++++++++++++++++ itests/kit/evm.go | 6 +++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/itests/fevm_test.go b/itests/fevm_test.go index 3018bf63d..068df49ef 100644 --- a/itests/fevm_test.go +++ b/itests/fevm_test.go @@ -844,6 +844,39 @@ func TestFEVMBareTransferTriggersSmartContractLogic(t *testing.T) { require.Len(t, receipt.Logs, 1) } +// This test ensures that we can deploy new contracts from a solidity call to `transfer` without +// exceeding the 10M gas limit. +func TestFEVMTestDeployOnTransfer(t *testing.T) { + ctx, cancel, client := kit.SetupFEVMTest(t) + defer cancel() + + fromAddr := client.DefaultKey.Address + t.Log("from - ", fromAddr) + + //create contract A + filenameStorage := "contracts/ValueSender.hex" + fromAddr, contractAddr := client.EVM().DeployContractFromFilename(ctx, filenameStorage) + + //send to some random address. + params := [32]byte{} + params[30] = 0xff + randomAddr, err := ethtypes.CastEthAddress(params[12:]) + value := big.NewInt(100) + entryPoint := kit.CalcFuncSignature("sendEthToB(address)") + require.NoError(t, err) + ret, err := client.EVM().InvokeSolidityWithValue(ctx, fromAddr, contractAddr, entryPoint, params[:], value) + require.NoError(t, err) + require.True(t, ret.Receipt.ExitCode.IsSuccess()) + + balance, err := client.EVM().EthGetBalance(ctx, randomAddr, "latest") + require.NoError(t, err) + require.Equal(t, value.Int, balance.Int) + + filAddr, err := randomAddr.ToFilecoinAddress() + require.NoError(t, err) + client.AssertActorType(ctx, filAddr, manifest.PlaceholderKey) +} + func TestFEVMProxyUpgradeable(t *testing.T) { ctx, cancel, client := kit.SetupFEVMTest(t) defer cancel() diff --git a/itests/kit/evm.go b/itests/kit/evm.go index 3cbfcd5f2..c98795f26 100644 --- a/itests/kit/evm.go +++ b/itests/kit/evm.go @@ -104,6 +104,10 @@ func (e *EVM) DeployContractFromFilename(ctx context.Context, binFilename string } func (e *EVM) InvokeSolidity(ctx context.Context, sender address.Address, target address.Address, selector []byte, inputData []byte) (*api.MsgLookup, error) { + return e.InvokeSolidityWithValue(ctx, sender, target, selector, inputData, big.Zero()) +} + +func (e *EVM) InvokeSolidityWithValue(ctx context.Context, sender address.Address, target address.Address, selector []byte, inputData []byte, value big.Int) (*api.MsgLookup, error) { params := append(selector, inputData...) var buffer bytes.Buffer err := cbg.WriteByteArray(&buffer, params) @@ -115,7 +119,7 @@ func (e *EVM) InvokeSolidity(ctx context.Context, sender address.Address, target msg := &types.Message{ To: target, From: sender, - Value: big.Zero(), + Value: value, Method: builtintypes.MethodsEVM.InvokeContract, GasLimit: build.BlockGasLimit, // note: we hardcode block gas limit due to slightly broken gas estimation - https://github.com/filecoin-project/lotus/issues/10041 Params: params,