-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add time to the sdk.Context used in PrepareProposal (#2515)
## Overview I'm not sure if this fixes all of #2454, but it at least fixes one bug similar to it. The fix in this PR allows for the antehandlers that are ran during prepare proposal to have access to a time close to the actual block time. It does this by simply adding `time.Now` to the header used for antehandler state access. ## Checklist - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [x] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords --------- Co-authored-by: Rootul P <[email protected]> (cherry picked from commit 9617549) # Conflicts: # app/test/fuzz_abci_test.go
- Loading branch information
1 parent
10574fa
commit e07c0b3
Showing
8 changed files
with
139 additions
and
5 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,100 @@ | ||
package app_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
"github.com/celestiaorg/celestia-app/pkg/user" | ||
"github.com/celestiaorg/celestia-app/test/util/testfactory" | ||
"github.com/celestiaorg/celestia-app/test/util/testnode" | ||
"github.com/cosmos/cosmos-sdk/crypto/hd" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
tmrand "github.com/tendermint/tendermint/libs/rand" | ||
) | ||
|
||
// TestTimeInPrepareProposalContext checks for an edge case where the block time | ||
// needs to be included in the sdk.Context that is being used in the | ||
// antehandlers. If a time is not included in the context, then the second | ||
// transaction in this test will always be filtered out, result in vesting | ||
// accounts never being able to spend funds. | ||
func TestTimeInPrepareProposalContext(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping TestTimeInPrepareProposalContext test in short mode.") | ||
} | ||
accounts := make([]string, 35) | ||
for i := 0; i < len(accounts); i++ { | ||
accounts[i] = tmrand.Str(9) | ||
} | ||
cfg := testnode.DefaultConfig().WithAccounts(accounts) | ||
cctx, _, _ := testnode.NewNetwork(t, cfg) | ||
ecfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) | ||
vestAccName := "vesting" | ||
type test struct { | ||
name string | ||
msgFunc func() (msgs []sdk.Msg, signer string) | ||
expectedCode uint32 | ||
} | ||
tests := []test{ | ||
{ | ||
name: "create continuous vesting account with a start time in the future", | ||
msgFunc: func() (msgs []sdk.Msg, signer string) { | ||
_, _, err := cctx.Keyring.NewMnemonic(vestAccName, keyring.English, "", "", hd.Secp256k1) | ||
require.NoError(t, err) | ||
sendAcc := accounts[0] | ||
sendingAccAddr := testfactory.GetAddress(cctx.Keyring, sendAcc) | ||
vestAccAddr := testfactory.GetAddress(cctx.Keyring, vestAccName) | ||
msg := vestingtypes.NewMsgCreateVestingAccount( | ||
sendingAccAddr, | ||
vestAccAddr, | ||
sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(1000000))), | ||
time.Now().Unix(), | ||
time.Now().Add(time.Second*100).Unix(), | ||
false, | ||
) | ||
return []sdk.Msg{msg}, sendAcc | ||
}, | ||
expectedCode: abci.CodeTypeOK, | ||
}, | ||
{ | ||
name: "send funds from the vesting account after it has been created", | ||
msgFunc: func() (msgs []sdk.Msg, signer string) { | ||
sendAcc := accounts[1] | ||
sendingAccAddr := testfactory.GetAddress(cctx.Keyring, sendAcc) | ||
vestAccAddr := testfactory.GetAddress(cctx.Keyring, vestAccName) | ||
msg := banktypes.NewMsgSend( | ||
vestAccAddr, | ||
sendingAccAddr, | ||
sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(1))), | ||
) | ||
return []sdk.Msg{msg}, vestAccName | ||
}, | ||
expectedCode: abci.CodeTypeOK, | ||
}, | ||
} | ||
|
||
// sign and submit the transactions | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
msgs, account := tt.msgFunc() | ||
addr := testfactory.GetAddress(cctx.Keyring, account) | ||
signer, err := user.SetupSigner(cctx.GoContext(), cctx.Keyring, cctx.GRPCClient, addr, ecfg) | ||
require.NoError(t, err) | ||
res, err := signer.SubmitTx(cctx.GoContext(), msgs, user.SetGasLimit(1000000), user.SetFee(1)) | ||
if tt.expectedCode != abci.CodeTypeOK { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
require.NotNil(t, res) | ||
assert.Equal(t, tt.expectedCode, res.Code, res.RawLog) | ||
}) | ||
} | ||
} |
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