-
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.
reorder
transfer
checks so as to ensure sending more money than you…
… have to yourself fails with an error (fixing issue 7596) PR #7637, also adds tests to make sure behavior is correct across versions.
- Loading branch information
Showing
4 changed files
with
174 additions
and
28 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
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,102 @@ | ||
package itests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-state-types/network" | ||
|
||
"github.com/filecoin-project/go-state-types/big" | ||
"github.com/filecoin-project/go-state-types/exitcode" | ||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/itests/kit" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
|
||
// these tests check that the versioned code in vm.transfer is functioning correctly across versions! | ||
// we reordered the checks to make sure that a transaction with too much money in it sent to yourself will fail instead of succeeding as a noop | ||
// more info in this PR! https://github.com/filecoin-project/lotus/pull/7637 | ||
func TestSelfSentTxnV15(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
kit.QuietMiningLogs() | ||
|
||
client15, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.GenesisNetworkVersion(network.Version15)) | ||
ens.InterconnectAll().BeginMining(10 * time.Millisecond) | ||
|
||
bal, err := client15.WalletBalance(ctx, client15.DefaultKey.Address) | ||
require.NoError(t, err) | ||
|
||
// send self half of account balance | ||
msgHalfBal := &types.Message{ | ||
From: client15.DefaultKey.Address, | ||
To: client15.DefaultKey.Address, | ||
Value: big.Div(bal, big.NewInt(2)), | ||
} | ||
smHalfBal, err := client15.MpoolPushMessage(ctx, msgHalfBal, nil) | ||
require.NoError(t, err) | ||
mLookup, err := client15.StateWaitMsg(ctx, smHalfBal.Cid(), 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) | ||
|
||
msgOverBal := &types.Message{ | ||
From: client15.DefaultKey.Address, | ||
To: client15.DefaultKey.Address, | ||
Value: big.Mul(big.NewInt(2), bal), | ||
GasLimit: 10000000000, | ||
GasPremium: big.NewInt(10000000000), | ||
GasFeeCap: big.NewInt(100000000000), | ||
Nonce: 1, | ||
} | ||
smOverBal, err := client15.WalletSignMessage(ctx, client15.DefaultKey.Address, msgOverBal) | ||
require.NoError(t, err) | ||
smcid, err := client15.MpoolPush(ctx, smOverBal) | ||
require.NoError(t, err) | ||
mLookup, err = client15.StateWaitMsg(ctx, smcid, 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
require.Equal(t, exitcode.SysErrInsufficientFunds, mLookup.Receipt.ExitCode) | ||
} | ||
|
||
func TestSelfSentTxnV14(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
kit.QuietMiningLogs() | ||
|
||
client14, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.GenesisNetworkVersion(network.Version14)) | ||
ens.InterconnectAll().BeginMining(10 * time.Millisecond) | ||
|
||
bal, err := client14.WalletBalance(ctx, client14.DefaultKey.Address) | ||
require.NoError(t, err) | ||
|
||
// send self half of account balance | ||
msgHalfBal := &types.Message{ | ||
From: client14.DefaultKey.Address, | ||
To: client14.DefaultKey.Address, | ||
Value: big.Div(bal, big.NewInt(2)), | ||
} | ||
smHalfBal, err := client14.MpoolPushMessage(ctx, msgHalfBal, nil) | ||
require.NoError(t, err) | ||
mLookup, err := client14.StateWaitMsg(ctx, smHalfBal.Cid(), 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) | ||
|
||
msgOverBal := &types.Message{ | ||
From: client14.DefaultKey.Address, | ||
To: client14.DefaultKey.Address, | ||
Value: big.Mul(big.NewInt(2), bal), | ||
GasLimit: 10000000000, | ||
GasPremium: big.NewInt(10000000000), | ||
GasFeeCap: big.NewInt(100000000000), | ||
Nonce: 1, | ||
} | ||
smOverBal, err := client14.WalletSignMessage(ctx, client14.DefaultKey.Address, msgOverBal) | ||
require.NoError(t, err) | ||
smcid, err := client14.MpoolPush(ctx, smOverBal) | ||
require.NoError(t, err) | ||
mLookup, err = client14.StateWaitMsg(ctx, smcid, 3, api.LookbackNoLimit, true) | ||
require.NoError(t, err) | ||
require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) | ||
} |