eth: FIP-0055: implement final version of transitory delegated signature. (#10239)
This commit is contained in:
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/itests/kit"
|
||||
)
|
||||
|
||||
// TestEthAccountAbstraction goes over the account abstraction workflow:
|
||||
// TestEthAccountAbstraction goes over the placeholder creation and promotion workflow:
|
||||
// - an placeholder is created when it receives a message
|
||||
// - the placeholder turns into an EOA when it sends a message
|
||||
func TestEthAccountAbstraction(t *testing.T) {
|
||||
@@ -67,7 +67,8 @@ func TestEthAccountAbstraction(t *testing.T) {
|
||||
msgFromPlaceholder := &types.Message{
|
||||
From: placeholderAddress,
|
||||
// self-send because an "eth tx payload" can't be to a filecoin address?
|
||||
To: placeholderAddress,
|
||||
To: placeholderAddress,
|
||||
Method: builtin2.MethodsEVM.InvokeContract,
|
||||
}
|
||||
msgFromPlaceholder, err = client.GasEstimateMessageGas(ctx, msgFromPlaceholder, nil, types.EmptyTSK)
|
||||
require.NoError(t, err)
|
||||
@@ -100,9 +101,10 @@ func TestEthAccountAbstraction(t *testing.T) {
|
||||
// Send another message, it should succeed without any code CID changes
|
||||
|
||||
msgFromPlaceholder = &types.Message{
|
||||
From: placeholderAddress,
|
||||
To: placeholderAddress,
|
||||
Nonce: 1,
|
||||
From: placeholderAddress,
|
||||
To: placeholderAddress,
|
||||
Method: builtin2.MethodsEVM.InvokeContract,
|
||||
Nonce: 1,
|
||||
}
|
||||
|
||||
msgFromPlaceholder, err = client.GasEstimateMessageGas(ctx, msgFromPlaceholder, nil, types.EmptyTSK)
|
||||
@@ -152,9 +154,10 @@ func TestEthAccountAbstractionFailure(t *testing.T) {
|
||||
|
||||
// create a placeholder actor at the target address
|
||||
msgCreatePlaceholder := &types.Message{
|
||||
From: client.DefaultKey.Address,
|
||||
To: placeholderAddress,
|
||||
Value: abi.TokenAmount(types.MustParseFIL("100")),
|
||||
From: client.DefaultKey.Address,
|
||||
To: placeholderAddress,
|
||||
Value: abi.TokenAmount(types.MustParseFIL("100")),
|
||||
Method: builtin2.MethodsEVM.InvokeContract,
|
||||
}
|
||||
smCreatePlaceholder, err := client.MpoolPushMessage(ctx, msgCreatePlaceholder, nil)
|
||||
require.NoError(t, err)
|
||||
@@ -172,9 +175,10 @@ func TestEthAccountAbstractionFailure(t *testing.T) {
|
||||
|
||||
// send a message from the placeholder address
|
||||
msgFromPlaceholder := &types.Message{
|
||||
From: placeholderAddress,
|
||||
To: placeholderAddress,
|
||||
Value: abi.TokenAmount(types.MustParseFIL("20")),
|
||||
From: placeholderAddress,
|
||||
To: placeholderAddress,
|
||||
Value: abi.TokenAmount(types.MustParseFIL("20")),
|
||||
Method: builtin2.MethodsEVM.InvokeContract,
|
||||
}
|
||||
msgFromPlaceholder, err = client.GasEstimateMessageGas(ctx, msgFromPlaceholder, nil, types.EmptyTSK)
|
||||
require.NoError(t, err)
|
||||
@@ -209,10 +213,11 @@ func TestEthAccountAbstractionFailure(t *testing.T) {
|
||||
// Send a valid message now, it should succeed without any code CID changes
|
||||
|
||||
msgFromPlaceholder = &types.Message{
|
||||
From: placeholderAddress,
|
||||
To: placeholderAddress,
|
||||
Nonce: 1,
|
||||
Value: abi.NewTokenAmount(1),
|
||||
From: placeholderAddress,
|
||||
To: placeholderAddress,
|
||||
Nonce: 1,
|
||||
Value: abi.NewTokenAmount(1),
|
||||
Method: builtin2.MethodsEVM.InvokeContract,
|
||||
}
|
||||
|
||||
msgFromPlaceholder, err = client.GasEstimateMessageGas(ctx, msgFromPlaceholder, nil, types.EmptyTSK)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"github.com/filecoin-project/go-state-types/exitcode"
|
||||
"github.com/filecoin-project/go-state-types/manifest"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
||||
@@ -786,3 +788,58 @@ func TestFEVMDestroyCreate2(t *testing.T) {
|
||||
require.Equal(t, ethFromAddr, senderSecondCall)
|
||||
|
||||
}
|
||||
|
||||
func TestFEVMBareTransferTriggersSmartContractLogic(t *testing.T) {
|
||||
ctx, cancel, client := kit.SetupFEVMTest(t)
|
||||
defer cancel()
|
||||
|
||||
// This contract emits an event on receiving value.
|
||||
filename := "contracts/ValueSender.hex"
|
||||
_, contractAddr := client.EVM().DeployContractFromFilename(ctx, filename)
|
||||
|
||||
accctKey, accntEth, accntFil := client.EVM().NewAccount()
|
||||
kit.SendFunds(ctx, t, client, accntFil, types.FromFil(10))
|
||||
|
||||
contractEth, err := ethtypes.EthAddressFromFilecoinAddress(contractAddr)
|
||||
require.NoError(t, err)
|
||||
|
||||
gaslimit, err := client.EthEstimateGas(ctx, ethtypes.EthCall{
|
||||
From: &accntEth,
|
||||
To: &contractEth,
|
||||
Value: ethtypes.EthBigInt(big.NewInt(100)),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
maxPriorityFeePerGas, err := client.EthMaxPriorityFeePerGas(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
tx := ethtypes.EthTxArgs{
|
||||
ChainID: build.Eip155ChainId,
|
||||
Value: big.NewInt(100),
|
||||
Nonce: 0,
|
||||
To: &contractEth,
|
||||
MaxFeePerGas: types.NanoFil,
|
||||
MaxPriorityFeePerGas: big.Int(maxPriorityFeePerGas),
|
||||
GasLimit: int(gaslimit),
|
||||
V: big.Zero(),
|
||||
R: big.Zero(),
|
||||
S: big.Zero(),
|
||||
}
|
||||
|
||||
client.EVM().SignTransaction(&tx, accctKey.PrivateKey)
|
||||
|
||||
hash := client.EVM().SubmitTransaction(ctx, &tx)
|
||||
|
||||
var receipt *api.EthTxReceipt
|
||||
for i := 0; i < 1000; i++ {
|
||||
receipt, err = client.EthGetTransactionReceipt(ctx, hash)
|
||||
require.NoError(t, err)
|
||||
if receipt != nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
// The receive() function emits one log, that's how we know we hit it.
|
||||
require.Len(t, receipt.Logs, 1)
|
||||
}
|
||||
|
||||
+2
-1
@@ -354,7 +354,7 @@ func SetupFEVMTest(t *testing.T) (context.Context, context.CancelFunc, *TestFull
|
||||
return ctx, cancel, client
|
||||
}
|
||||
|
||||
func (e *EVM) TransferValueOrFail(ctx context.Context, fromAddr address.Address, toAddr address.Address, sendAmount big.Int) {
|
||||
func (e *EVM) TransferValueOrFail(ctx context.Context, fromAddr address.Address, toAddr address.Address, sendAmount big.Int) *api.MsgLookup {
|
||||
sendMsg := &types.Message{
|
||||
From: fromAddr,
|
||||
To: toAddr,
|
||||
@@ -365,6 +365,7 @@ func (e *EVM) TransferValueOrFail(ctx context.Context, fromAddr address.Address,
|
||||
mLookup, err := e.StateWaitMsg(ctx, signedMsg.Cid(), 3, api.LookbackNoLimit, true)
|
||||
require.NoError(e.t, err)
|
||||
require.Equal(e.t, exitcode.Ok, mLookup.Receipt.ExitCode)
|
||||
return mLookup
|
||||
}
|
||||
|
||||
func NewEthFilterBuilder() *EthFilterBuilder {
|
||||
|
||||
Reference in New Issue
Block a user