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
This commit is contained in:
Steven Allen 2023-02-17 13:29:53 -08:00 committed by GitHub
parent 8f1c23296e
commit 73102e9432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -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()

View File

@ -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,