-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #4384: allow splitting withdrawal txs
* allow splitting withdrawal txs * updating .pending * small cleanup * fixing build issue * Update x/distribution/client/cli/tx.go Co-Authored-By: Alessio Treglia <quadrispro@ubuntu.com> * updating usage text * fixing merge issue * changes based on the review * adding unit tests * Update x/distribution/client/cli/tx.go Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * adjustments from review
- Loading branch information
1 parent
e53d233
commit 68036ec
Showing
3 changed files
with
121 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#4384- Allow splitting withdrawal transaction in several chunks |
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,77 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/client/utils" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
"testing" | ||
) | ||
|
||
func createFakeTxBuilder() authtxb.TxBuilder { | ||
cdc := codec.New() | ||
return authtxb.NewTxBuilder( | ||
utils.GetTxEncoder(cdc), | ||
123, | ||
9876, | ||
0, | ||
1.2, | ||
false, | ||
"test_chain", | ||
"hello", | ||
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))), | ||
sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDecWithPrec(10000, sdk.Precision))}, | ||
) | ||
} | ||
|
||
func Test_splitAndCall_NoMessages(t *testing.T) { | ||
ctx := context.CLIContext{} | ||
txBldr := createFakeTxBuilder() | ||
|
||
err := splitAndApply(nil, ctx, txBldr, nil, 10) | ||
assert.NoError(t, err, "") | ||
} | ||
|
||
func Test_splitAndCall_Splitting(t *testing.T) { | ||
ctx := context.CLIContext{} | ||
txBldr := createFakeTxBuilder() | ||
|
||
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) | ||
|
||
// Add five messages | ||
msgs := []sdk.Msg{ | ||
sdk.NewTestMsg(addr), | ||
sdk.NewTestMsg(addr), | ||
sdk.NewTestMsg(addr), | ||
sdk.NewTestMsg(addr), | ||
sdk.NewTestMsg(addr), | ||
} | ||
|
||
// Keep track of number of calls | ||
const chunkSize = 2 | ||
|
||
callCount := 0 | ||
err := splitAndApply( | ||
func(ctx context.CLIContext, txBldr authtxb.TxBuilder, msgs []sdk.Msg) error { | ||
callCount += 1 | ||
|
||
assert.NotNil(t, ctx) | ||
assert.NotNil(t, txBldr) | ||
assert.NotNil(t, msgs) | ||
|
||
if callCount < 3 { | ||
assert.Equal(t, len(msgs), 2) | ||
} else { | ||
assert.Equal(t, len(msgs), 1) | ||
} | ||
|
||
return nil | ||
}, | ||
ctx, txBldr, msgs, chunkSize) | ||
|
||
assert.NoError(t, err, "") | ||
assert.Equal(t, 3, callCount) | ||
} |