-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add data max size and emit deposit hook events
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"cosmossdk.io/math" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/initia-labs/OPinit/x/opchild/keeper" | ||
"github.com/initia-labs/OPinit/x/opchild/types" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/crypto/sha3" | ||
) | ||
|
||
func Test_MsgServer_Deposit_HookEvents(t *testing.T) { | ||
ctx, input := createDefaultTestInput(t) | ||
ms := keeper.NewMsgServerImpl(&input.OPChildKeeper) | ||
|
||
bz := sha3.Sum256([]byte("test_token")) | ||
denom := "l2/" + hex.EncodeToString(bz[:]) | ||
|
||
require.Equal(t, math.ZeroInt(), input.BankKeeper.GetBalance(ctx, addrs[1], denom).Amount) | ||
|
||
// empty deposit to create account | ||
priv, _, addr := keyPubAddr() | ||
msg := types.NewMsgFinalizeTokenDeposit(addrsStr[0], addrsStr[1], addr.String(), sdk.NewCoin(denom, math.ZeroInt()), 1, 1, "test_token", nil) | ||
_, err := ms.FinalizeTokenDeposit(ctx, msg) | ||
require.NoError(t, err) | ||
|
||
// create hook data | ||
acc := input.AccountKeeper.GetAccount(ctx, addr) | ||
require.NotNil(t, acc) | ||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv}, []uint64{acc.GetAccountNumber()}, []uint64{0} | ||
from, _ := input.AccountKeeper.AddressCodec().BytesToString(addr) | ||
to, _ := input.AccountKeeper.AddressCodec().BytesToString(addrs[2]) | ||
|
||
signedTxBz, err := input.EncodingConfig.TxConfig.TxEncoder()(generateTestTx( | ||
t, input, | ||
[]sdk.Msg{ | ||
types.NewMsgInitiateTokenWithdrawal(from, to, sdk.NewCoin(denom, math.NewInt(50))), | ||
}, | ||
privs, accNums, accSeqs, sdk.UnwrapSDKContext(ctx).ChainID(), | ||
)) | ||
require.NoError(t, err) | ||
|
||
// valid deposit | ||
ctx = sdk.UnwrapSDKContext(ctx).WithEventManager(sdk.NewEventManager()) | ||
msg = types.NewMsgFinalizeTokenDeposit(addrsStr[0], addrsStr[1], addr.String(), sdk.NewCoin(denom, math.NewInt(100)), 2, 1, "test_token", signedTxBz) | ||
_, err = ms.FinalizeTokenDeposit(ctx, msg) | ||
require.NoError(t, err) | ||
|
||
withdrawalEventFound := false | ||
for _, event := range sdk.UnwrapSDKContext(ctx).EventManager().Events() { | ||
if event.Type == types.EventTypeInitiateTokenWithdrawal { | ||
withdrawalEventFound = true | ||
} else if event.Type == types.EventTypeFinalizeTokenDeposit { | ||
require.Equal(t, event.Attributes[len(event.Attributes)-1].Key, types.AttributeKeySuccess) | ||
require.Equal(t, event.Attributes[len(event.Attributes)-1].Value, "true") | ||
} | ||
} | ||
|
||
// but no event was emitted by hooks | ||
require.True(t, withdrawalEventFound) | ||
} |
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