cdf3812e40
Co-authored-by: Steven Allen <steven@stebalien.com> Co-authored-by: Raul Kripalani <raulk@users.noreply.github.com> Co-authored-by: Kevin Li <ychiaoli18@users.noreply.github.com> Co-authored-by: vyzo <vyzo@hackzen.org> Co-authored-by: Ian Davis <nospam@iandavis.com> Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com> Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> Co-authored-by: Jennifer Wang <jiayingw703@gmail.com> Co-authored-by: Geoff Stuart <geoff.vball@gmail.com> Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai> Co-authored-by: Shrenuj Bansal <108157875+shrenujbansal@users.noreply.github.com> Co-authored-by: Geoff Stuart <geoffrey.stuart@protocol.ai> Co-authored-by: Aayush Rajasekaran <aayushrajasekaran@Aayushs-MacBook-Pro.local> Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com> Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>
98 lines
3.0 KiB
Go
98 lines
3.0 KiB
Go
package itests
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
|
)
|
|
|
|
func TestEthGetBalanceExistingF4address(t *testing.T) {
|
|
blockTime := 100 * time.Millisecond
|
|
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
|
|
_, ethAddr, deployer := client.EVM().NewAccount()
|
|
|
|
fundAmount := types.FromFil(0)
|
|
// send some funds to the f410 address
|
|
kit.SendFunds(ctx, t, client, deployer, fundAmount)
|
|
|
|
balance, err := client.EthGetBalance(ctx, ethAddr, "latest")
|
|
require.NoError(t, err)
|
|
require.Equal(t, balance, ethtypes.EthBigInt{Int: fundAmount.Int})
|
|
}
|
|
|
|
func TestEthGetBalanceNonExistentF4address(t *testing.T) {
|
|
blockTime := 100 * time.Millisecond
|
|
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
|
|
_, ethAddr, _ := client.EVM().NewAccount()
|
|
|
|
balance, err := client.EthGetBalance(ctx, ethAddr, "latest")
|
|
require.NoError(t, err)
|
|
require.Equal(t, balance, ethtypes.EthBigIntZero)
|
|
}
|
|
|
|
func TestEthGetBalanceExistentIDMaskedAddr(t *testing.T) {
|
|
blockTime := 100 * time.Millisecond
|
|
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
|
|
faddr, err := client.WalletDefaultAddress(ctx)
|
|
require.NoError(t, err)
|
|
fid, err := client.StateLookupID(ctx, faddr, types.EmptyTSK)
|
|
require.NoError(t, err)
|
|
|
|
ethAddr, err := ethtypes.EthAddressFromFilecoinAddress(fid)
|
|
require.NoError(t, err)
|
|
|
|
balance, err := client.WalletBalance(ctx, fid)
|
|
require.NoError(t, err)
|
|
|
|
ebal, err := client.EthGetBalance(ctx, ethAddr, "latest")
|
|
require.NoError(t, err)
|
|
require.Equal(t, ebal, ethtypes.EthBigInt{Int: balance.Int})
|
|
}
|
|
|
|
func TestEthGetBalanceBuiltinActor(t *testing.T) {
|
|
blockTime := 100 * time.Millisecond
|
|
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
|
|
ens.InterconnectAll().BeginMining(blockTime)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
|
|
// Address for market actor
|
|
fid, err := address.NewFromString("f05")
|
|
require.NoError(t, err)
|
|
|
|
kit.SendFunds(ctx, t, client, fid, abi.TokenAmount{Int: big.NewInt(10).Int})
|
|
|
|
ethAddr, err := ethtypes.EthAddressFromFilecoinAddress(fid)
|
|
require.NoError(t, err)
|
|
|
|
ebal, err := client.EthGetBalance(ctx, ethAddr, "latest")
|
|
require.NoError(t, err)
|
|
require.Equal(t, ethtypes.EthBigInt{Int: big.NewInt(10).Int}, ebal)
|
|
}
|