-
Notifications
You must be signed in to change notification settings - Fork 326
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 (backport #2515
) (#2534) This is an automatic backport of pull request #2515 done by [Mergify](https://mergify.com). Cherry-pick of 9617549 has failed: ``` On branch mergify/bp/v1.x/pr-2515 Your branch is up to date with 'origin/v1.x'. You are currently cherry-picking commit 9617549. (fix conflicts and run "git cherry-pick --continue") (use "git cherry-pick --skip" to skip this patch) (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: modified: Makefile modified: app/prepare_proposal.go new file: app/test/prepare_proposal_context_test.go modified: app/test/prepare_proposal_test.go modified: app/test/process_proposal_test.go modified: go.mod modified: go.sum Unmerged paths: (use "git add <file>..." to mark resolution) both modified: app/test/fuzz_abci_test.go ``` To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details> --------- Co-authored-by: Evan Forbes <[email protected]> Co-authored-by: evan-forbes <[email protected]>
- Loading branch information
1 parent
10574fa
commit af17626
Showing
8 changed files
with
137 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