-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add time to the sdk.Context used in PrepareProposal #2515
Changes from all commits
ee482b0
9f896e8
5ad8371
0f48861
f5710fc
d873db1
d80e551
2baaf49
8e2b4d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() { | ||
Comment on lines
+23
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could have included this in the standard cosmos-sdk test that we're already running, however since the tx needs to be second it felt a bit too hacky to do that |
||
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(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a start time in the future as is stated in the test name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will grab this in a followup |
||
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, | ||
}, | ||
} | ||
Comment on lines
+46
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one additional test we can do is to have a third test case where we attempt to send too much and expect it to fail. I have a commit with this ready, however I'm worried that it will cause flakiness do to the process requiring a specific time delay window. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it will be flaky if you set the end time well in the future and try send all the funds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah good point, sorry I was not clear enough. the thing that I was trying to test with the additional case here was not just that a tx would fail if there was not enough of a spendable balance, I think we have that somehwere already (#2004 iirc). That wouldn't be flakey. I was trying to create a test that checks that puts us in the exact scenario we would get in if we used |
||
|
||
// 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) | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we defer to using integration tests too often when unit tests would suffice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2533