-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
itests: Add tests for eth get balance and transaction submits (#9966)
* Add tests for eth get balance and transaction submits * fix lint * one more lint * Add contract invocation test * address comments * fix lint * address final comment * make gen and fix lint as always
- Loading branch information
1 parent
95501b7
commit 3456d90
Showing
4 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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) | ||
} |
Oops, something went wrong.