Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Aug 12, 2024
1 parent 6cee212 commit e35456d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions x/ibc-hooks/move-hooks/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
59 changes: 58 additions & 1 deletion x/ibc-hooks/move-hooks/receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}

0 comments on commit e35456d

Please sign in to comment.