Skip to content

Commit

Permalink
test: eth: make sure we can deploy a new placeholder on transfer (#10281
Browse files Browse the repository at this point in the history
)

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 filecoin-project/ref-fvm#1670
  • Loading branch information
Stebalien authored Feb 17, 2023
1 parent 8f1c232 commit 73102e9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
33 changes: 33 additions & 0 deletions itests/fevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion itests/kit/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 73102e9

Please sign in to comment.