From e35456d5218165c2c5bd7d54e5467ad35341de98 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:45:07 +0900 Subject: [PATCH] add testcase --- x/ibc-hooks/move-hooks/receive.go | 2 + x/ibc-hooks/move-hooks/receive_test.go | 59 +++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/x/ibc-hooks/move-hooks/receive.go b/x/ibc-hooks/move-hooks/receive.go index 87bf4e1a..05a544a1 100644 --- a/x/ibc-hooks/move-hooks/receive.go +++ b/x/ibc-hooks/move-hooks/receive.go @@ -75,11 +75,13 @@ func (h MoveHooks) onRecvIcs721Packet( ) ibcexported.Acknowledgement { isMoveRouted, hookData, err := validateAndParseMemo(data.GetMemo()) if !isMoveRouted || hookData.Message == nil { + fmt.Println("SIBONG") return im.App.OnRecvPacket(ctx, packet, relayer) } else if err != nil { return newEmitErrorAcknowledgement(err) } + fmt.Println("SIBONG") msg := hookData.Message if allowed, err := h.checkACL(im, ctx, msg.ModuleAddress); err != nil { return newEmitErrorAcknowledgement(err) diff --git a/x/ibc-hooks/move-hooks/receive_test.go b/x/ibc-hooks/move-hooks/receive_test.go index a0897a48..41909ad0 100644 --- a/x/ibc-hooks/move-hooks/receive_test.go +++ b/x/ibc-hooks/move-hooks/receive_test.go @@ -115,7 +115,7 @@ func Test_OnReceivePacket_ICS721(t *testing.T) { require.True(t, ack.Success()) } -func Test_onReceiveIcs20Packet_memo_ICS721(t *testing.T) { +func Test_onReceivePacket_memo_ICS721(t *testing.T) { ctx, input := createDefaultTestInput(t) _, _, addr := keyPubAddr() @@ -169,3 +169,60 @@ func Test_onReceiveIcs20Packet_memo_ICS721(t *testing.T) { require.NoError(t, err) require.Equal(t, "\"1\"", queryRes.Ret) } + +func Test_onReceivePacket_memo_ICS721_Wasm(t *testing.T) { + ctx, input := createDefaultTestInput(t) + _, _, addr := keyPubAddr() + + data := nfttransfertypes.NonFungibleTokenPacketDataWasm{ + ClassId: "classId", + ClassUri: "classUri", + ClassData: "classData", + TokenIds: []string{"tokenId"}, + TokenUris: []string{"tokenUri"}, + TokenData: []string{"tokenData"}, + Sender: addr.String(), + Receiver: "0x1::Counter::increase", + Memo: `{ + "move": { + "message": { + "module_address": "0x1", + "module_name": "Counter", + "function_name": "increase" + } + } + }`, + } + + dataBz, err := json.Marshal(&data) + require.NoError(t, err) + + // failed to due to acl + ack := input.IBCHooksMiddleware.OnRecvPacket(ctx, channeltypes.Packet{ + SourcePort: "wasm.contract_address", + Data: dataBz, + }, addr) + require.False(t, ack.Success()) + + // set acl + require.NoError(t, input.IBCHooksKeeper.SetAllowed(ctx, movetypes.ConvertVMAddressToSDKAddress(vmtypes.StdAddress), true)) + + // success + ack = input.IBCHooksMiddleware.OnRecvPacket(ctx, channeltypes.Packet{ + SourcePort: "wasm.contract_address", + Data: dataBz, + }, addr) + require.True(t, ack.Success()) + + // check the contract state + queryRes, err := input.MoveKeeper.ExecuteViewFunction( + ctx, + vmtypes.StdAddress, + "Counter", + "get", + []vmtypes.TypeTag{}, + [][]byte{}, + ) + require.NoError(t, err) + require.Equal(t, "\"1\"", queryRes.Ret) +}