itests: Test EAM interactions from accounts
This commit is contained in:
parent
7632f9bbba
commit
68e20cebd7
@ -11,6 +11,8 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
builtin2 "github.com/filecoin-project/go-state-types/builtin"
|
||||
"github.com/filecoin-project/go-state-types/builtin/v10/eam"
|
||||
"github.com/filecoin-project/go-state-types/exitcode"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
@ -313,3 +315,51 @@ func TestEthAccountAbstractionFailsFromEvmActor(t *testing.T) {
|
||||
require.Error(t, err, "expected gas estimation to fail")
|
||||
require.Contains(t, err.Error(), "SysErrSenderInvalid")
|
||||
}
|
||||
|
||||
func TestEthAccountManagerPermissions(t *testing.T) {
|
||||
kit.QuietMiningLogs()
|
||||
|
||||
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
|
||||
ens.InterconnectAll().BeginMining(10 * time.Millisecond)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
// setup f1/f3/f4 accounts
|
||||
|
||||
wsp, err := client.WalletNew(ctx, types.KTSecp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
wbl, err := client.WalletNew(ctx, types.KTBLS)
|
||||
require.NoError(t, err)
|
||||
|
||||
wdl, err := client.WalletNew(ctx, types.KTDelegated)
|
||||
require.NoError(t, err)
|
||||
|
||||
def := client.DefaultKey.Address
|
||||
|
||||
// send some funds
|
||||
client.ExpectSend(ctx, def, wsp, types.FromFil(10), "")
|
||||
client.ExpectSend(ctx, def, wbl, types.FromFil(10), "")
|
||||
client.ExpectSend(ctx, def, wdl, types.FromFil(10), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
// make sure that EAM only allows CreateExternal to be called by accounts
|
||||
client.ExpectSend(ctx, wsp, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "not one of supported (18)", client.MakeSendCall(builtin2.MethodsEAM.Create, &eam.CreateParams{Nonce: 0}))
|
||||
client.ExpectSend(ctx, wbl, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "not one of supported (18)", client.MakeSendCall(builtin2.MethodsEAM.Create, &eam.CreateParams{Nonce: 0}))
|
||||
client.ExpectSend(ctx, wdl, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "not one of supported (18)", client.MakeSendCall(builtin2.MethodsEAM.Create, &eam.CreateParams{Nonce: 0}))
|
||||
|
||||
client.ExpectSend(ctx, wsp, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "not one of supported (18)", client.MakeSendCall(builtin2.MethodsEAM.Create2, &eam.Create2Params{}))
|
||||
client.ExpectSend(ctx, wbl, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "not one of supported (18)", client.MakeSendCall(builtin2.MethodsEAM.Create2, &eam.Create2Params{}))
|
||||
client.ExpectSend(ctx, wdl, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "not one of supported (18)", client.MakeSendCall(builtin2.MethodsEAM.Create2, &eam.Create2Params{}))
|
||||
|
||||
contractHex, err := os.ReadFile("contracts/SimpleCoin.hex")
|
||||
require.NoError(t, err)
|
||||
contract, err := hex.DecodeString(string(contractHex))
|
||||
require.NoError(t, err)
|
||||
contractParams := abi.CborBytes(contract)
|
||||
|
||||
client.ExpectSend(ctx, wsp, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "", client.MakeSendCall(builtin2.MethodsEAM.CreateExternal, &contractParams))
|
||||
client.ExpectSend(ctx, wbl, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "", client.MakeSendCall(builtin2.MethodsEAM.CreateExternal, &contractParams))
|
||||
client.ExpectSend(ctx, wdl, builtin2.EthereumAddressManagerActorAddr, big.Zero(), "", client.MakeSendCall(builtin2.MethodsEAM.CreateExternal, &contractParams))
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package kit
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
@ -10,9 +11,11 @@ import (
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"github.com/stretchr/testify/require"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/exitcode"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/v1api"
|
||||
@ -124,6 +127,50 @@ func (f *TestFullNode) AssignPrivKey(pkey *Libp2p) {
|
||||
f.Pkey = pkey
|
||||
}
|
||||
|
||||
type SendCall struct {
|
||||
Method abi.MethodNum
|
||||
Params []byte
|
||||
}
|
||||
|
||||
func (f *TestFullNode) MakeSendCall(m abi.MethodNum, params cbg.CBORMarshaler) SendCall {
|
||||
var b bytes.Buffer
|
||||
err := params.MarshalCBOR(&b)
|
||||
require.NoError(f.t, err)
|
||||
return SendCall{
|
||||
Method: m,
|
||||
Params: b.Bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *TestFullNode) ExpectSend(ctx context.Context, from, to address.Address, value types.BigInt, errContains string, sc ...SendCall) *types.SignedMessage {
|
||||
msg := &types.Message{From: from, To: to, Value: value}
|
||||
|
||||
if len(sc) == 1 {
|
||||
msg.Method = sc[0].Method
|
||||
msg.Params = sc[0].Params
|
||||
}
|
||||
|
||||
_, err := f.GasEstimateMessageGas(ctx, msg, nil, types.EmptyTSK)
|
||||
if errContains != "" {
|
||||
require.ErrorContains(f.t, err, errContains)
|
||||
return nil
|
||||
}
|
||||
require.NoError(f.t, err)
|
||||
|
||||
if errContains == "" {
|
||||
m, err := f.MpoolPushMessage(ctx, msg, nil)
|
||||
require.NoError(f.t, err)
|
||||
|
||||
r, err := f.StateWaitMsg(ctx, m.Cid(), 1, api.LookbackNoLimit, true)
|
||||
require.NoError(f.t, err)
|
||||
|
||||
require.Equal(f.t, exitcode.Ok, r.Receipt.ExitCode)
|
||||
return m
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChainPredicate encapsulates a chain condition.
|
||||
type ChainPredicate func(set *types.TipSet) bool
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user