forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4add7f4
commit 2ca4787
Showing
5 changed files
with
227 additions
and
0 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
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,44 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
keepertest "github.com/wormhole-foundation/wormchain/testutil/keeper" | ||
"github.com/wormhole-foundation/wormchain/x/ibc-composability-mw/types" | ||
) | ||
|
||
// TestGenesis ensures genesis state can be initialiazed and exported correctly | ||
func TestGenesis(t *testing.T) { | ||
for _, tc := range []struct { | ||
dataInFlight map[string][]byte | ||
}{ | ||
{ | ||
dataInFlight: map[string][]byte{}, | ||
}, | ||
{ | ||
dataInFlight: map[string][]byte{ | ||
"key1": []byte("value1"), | ||
}, | ||
}, | ||
{ | ||
dataInFlight: map[string][]byte{ | ||
"key1": []byte("value1"), | ||
"key2": []byte("value2"), | ||
"key3": []byte("value3"), | ||
}, | ||
}, | ||
} { | ||
genesisState := types.GenesisState{ | ||
TransposedDataInFlight: tc.dataInFlight, | ||
} | ||
|
||
_, keeper, ctx := keepertest.WormholeKeeperAndIBCComposabilityMwKeeper(t) | ||
|
||
keeper.InitGenesis(ctx, genesisState) | ||
|
||
outputState := keeper.ExportGenesis(ctx) | ||
|
||
require.Equal(t, genesisState, *outputState) | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
wormchain/x/ibc-composability-mw/types/gateway_payload_test.go
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,85 @@ | ||
package types_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/wormhole-foundation/wormchain/x/ibc-composability-mw/types" | ||
) | ||
|
||
func TestGatewayPayloads(t *testing.T) { | ||
|
||
for _, tc := range []struct { | ||
memo string // use memo if present, otherwise marshal tbPayload with json | ||
tbPayload types.GatewayIbcTokenBridgePayload | ||
shouldErr bool | ||
}{ | ||
{ | ||
memo: "abc123", | ||
shouldErr: true, | ||
}, | ||
{ | ||
tbPayload: types.GatewayIbcTokenBridgePayload{}, | ||
shouldErr: true, | ||
}, | ||
{ | ||
tbPayload: types.GatewayIbcTokenBridgePayload{ | ||
GatewayIbcTokenBridgePayloadObj: types.GatewayIbcTokenBridgePayloadObj{ | ||
Transfer: types.GatewayTransfer{ | ||
Chain: 1, | ||
Recipient: []byte("recipient"), | ||
Fee: "0uworm", | ||
Nonce: 1, | ||
}, | ||
}, | ||
}, | ||
shouldErr: false, | ||
}, | ||
{ | ||
tbPayload: types.GatewayIbcTokenBridgePayload{ | ||
GatewayIbcTokenBridgePayloadObj: types.GatewayIbcTokenBridgePayloadObj{ | ||
TransferWithPayload: types.GatewayTransferWithPayload{ | ||
Chain: 1, | ||
Contract: []byte("contract"), | ||
Payload: []byte("{\"payload\":\"data\"}"), | ||
Nonce: 1, | ||
}, | ||
}, | ||
}, | ||
shouldErr: false, | ||
}, | ||
} { | ||
|
||
memo := tc.memo | ||
|
||
if memo == "" { | ||
bz, err := json.Marshal(tc.tbPayload) | ||
require.NoError(t, err) | ||
memo = string(bz) | ||
} | ||
|
||
payload, err := types.VerifyAndParseGatewayPayload(memo) | ||
|
||
if tc.shouldErr { | ||
require.Error(t, err) | ||
// continue to next case if err | ||
continue | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
|
||
// validate payload was parsed correctly | ||
if payload.NoPayload { | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.Transfer.Chain, payload.ChainId) | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.Transfer.Recipient, payload.Recipient) | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.Transfer.Fee, payload.Fee) | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.Transfer.Nonce, payload.Nonce) | ||
} else { | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.TransferWithPayload.Chain, payload.ChainId) | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.TransferWithPayload.Contract, payload.Recipient) | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.TransferWithPayload.Payload, payload.Payload) | ||
require.Equal(t, tc.tbPayload.GatewayIbcTokenBridgePayloadObj.TransferWithPayload.Nonce, payload.Nonce) | ||
} | ||
} | ||
} |
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,85 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/wormhole-foundation/wormchain/x/ibc-composability-mw/types" | ||
) | ||
|
||
func TestFormatIbcHooksMemo(t *testing.T) { | ||
|
||
ibcTranslatorContract := "wormhole123abc" | ||
|
||
for _, tc := range []struct { | ||
payload types.ParsedPayload | ||
shouldErr bool | ||
}{ | ||
// Normal w/ no payload | ||
{ | ||
payload: types.ParsedPayload{ | ||
NoPayload: true, | ||
ChainId: 1, | ||
Recipient: []byte{'a', 'b', 'c'}, | ||
Fee: "0uworm", | ||
Nonce: 1, | ||
Payload: nil, | ||
}, | ||
shouldErr: false, | ||
}, | ||
// Provide payload when unnecessary | ||
{ | ||
payload: types.ParsedPayload{ | ||
NoPayload: true, | ||
ChainId: 1, | ||
Recipient: []byte{'a', 'b', 'c'}, | ||
Fee: "0uworm", | ||
Nonce: 1, | ||
Payload: []byte("{\"payload\":\"data\"}"), | ||
}, | ||
shouldErr: false, | ||
}, | ||
// Normal w/ payload | ||
{ | ||
payload: types.ParsedPayload{ | ||
NoPayload: false, | ||
ChainId: 1, | ||
Recipient: []byte{'a', 'b', 'c'}, | ||
Fee: "0uworm", | ||
Nonce: 1, | ||
Payload: []byte("{\"payload\":\"data\"}"), | ||
}, | ||
shouldErr: false, | ||
}, | ||
// Nil payload should not err | ||
{ | ||
payload: types.ParsedPayload{ | ||
NoPayload: true, | ||
ChainId: 1, | ||
Recipient: []byte{'a', 'b', 'c'}, | ||
Fee: "0uworm", | ||
Nonce: 1, | ||
Payload: nil, | ||
}, | ||
shouldErr: false, | ||
}, | ||
} { | ||
res, err := types.FormatIbcHooksMemo(tc.payload, ibcTranslatorContract) | ||
|
||
if tc.shouldErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
require.NotNil(t, res) | ||
} | ||
|
||
if tc.payload.NoPayload { | ||
require.NotContains(t, res, "gateway_convert_and_transfer_with_payload") | ||
require.Contains(t, res, "recipient") | ||
} else { | ||
require.Contains(t, res, "gateway_convert_and_transfer_with_payload") | ||
require.NotContains(t, res, "recipient") | ||
require.Contains(t, res, "payload") | ||
} | ||
} | ||
} |
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,7 @@ | ||
package types_test | ||
|
||
import "testing" | ||
|
||
func TestFormatPfmMemo(t *testing.T) { | ||
|
||
} |