Skip to content

Commit

Permalink
Cleanup Tests & Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Sep 18, 2024
1 parent 74b1a44 commit 24eb4bd
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 35 deletions.
16 changes: 11 additions & 5 deletions wormchain/x/wormhole/keeper/allowlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

// TestAllowedAddressStore tests the setting, getting, and removing of allowed addresses
const (
WormholeAddress1 = "wormhole1du4amsmvx8yqr8whw7qc5m3c0zpwknmzelwqy6"
WormholeAddress2 = "wormhole13ztxpktzsng3ewkepe2w39ugxzfdf23teptu9n"
)

// TestAllowedAddressStore tests the setting, getting, and removing of allowed addresses.
func TestAllowedAddressStore(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

value := types.ValidatorAllowedAddress{
ValidatorAddress: "wormhole1du4amsmvx8yqr8whw7qc5m3c0zpwknmzelwqy6",
AllowedAddress: "wormhole13ztxpktzsng3ewkepe2w39ugxzfdf23teptu9n",
ValidatorAddress: WormholeAddress1,
AllowedAddress: WormholeAddress2,
Name: "User1",
}

Expand Down Expand Up @@ -53,6 +58,7 @@ func TestAllowedAddressStore(t *testing.T) {
require.False(t, hasAddr)
}

// TestValidatorAsAllowedAddress tests if a validator is a guardian or future validator.
func TestValidatorAsAllowedAddress(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

Expand Down Expand Up @@ -83,8 +89,8 @@ func TestValidatorAsAllowedAddress(t *testing.T) {
require.True(t, isVal)

// Check invalid addresses
_, found = k.GetGuardianValidatorByValidatorAddress(ctx, "wormhole13ztxpktzsng3ewkepe2w39ugxzfdf23teptu9n")
_, found = k.GetGuardianValidatorByValidatorAddress(ctx, WormholeAddress1)
require.False(t, found)
isVal = k.IsAddressValidatorOrFutureValidator(ctx, "wormhole13ztxpktzsng3ewkepe2w39ugxzfdf23teptu9n")
isVal = k.IsAddressValidatorOrFutureValidator(ctx, WormholeAddress1)
require.False(t, isVal)
}
6 changes: 3 additions & 3 deletions wormchain/x/wormhole/keeper/grpc_query_allowlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/wormhole-foundation/wormchain/x/wormhole/types"
)

// TestQueryAllowlist tests the allow list queries
// TestQueryAllowlist tests the allow list queries.
func TestQueryAllowlist(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

Expand All @@ -19,8 +19,8 @@ func TestQueryAllowlist(t *testing.T) {
require.Equal(t, 0, len(res.Allowlist))

value := types.ValidatorAllowedAddress{
ValidatorAddress: "wormhole1du4amsmvx8yqr8whw7qc5m3c0zpwknmzelwqy6",
AllowedAddress: "wormhole13ztxpktzsng3ewkepe2w39ugxzfdf23teptu9n",
ValidatorAddress: WormholeAddress1,
AllowedAddress: WormholeAddress2,
Name: "User1",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/wormhole-foundation/wormchain/x/wormhole/types"
)

// TestQueryIbcComposabilityMwContract tests querying of the IbcComposabilityMwContract
// TestQueryIbcComposabilityMwContract tests querying of the IbcComposabilityMwContract.
func TestQueryIbcComposabilityMwContract(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

Expand All @@ -23,7 +23,7 @@ func TestQueryIbcComposabilityMwContract(t *testing.T) {
require.Equal(t, "", res.ContractAddress)

// Set the contract in state store
contractAddr := "wormhole1du4amsmvx8yqr8whw7qc5m3c0zpwknmzelwqy6"
contractAddr := WormholeContractAddress1
k.StoreIbcComposabilityMwContract(ctx, types.IbcComposabilityMwContract{
ContractAddress: contractAddr,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

// TestLatestGuardianSetIndex tests the querying of the latest guardian set index
// TestLatestGuardianSetIndex tests the querying of the latest guardian set index.
func TestLatestGuardianSetIndex(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/wormhole-foundation/wormchain/x/wormhole/types"
)

// TestWasmInstantiateAllowlistAll tests the querying of the wasm instantiate allow list
// TestWasmInstantiateAllowlistAll tests the querying of the wasm instantiate allow list.
func TestWasmInstantiateAllowlistAll(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

Expand All @@ -24,7 +24,7 @@ func TestWasmInstantiateAllowlistAll(t *testing.T) {

// Set contract in allow list
contract := types.WasmInstantiateAllowedContractCodeId{
ContractAddress: "wormhole1du4amsmvx8yqr8whw7qc5m3c0zpwknmzelwqy6",
ContractAddress: WormholeContractAddress1,
CodeId: 1,
}
k.SetWasmInstantiateAllowlist(ctx, contract)
Expand Down
2 changes: 1 addition & 1 deletion wormchain/x/wormhole/keeper/ibc_composability_mw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/wormhole-foundation/wormchain/x/wormhole/types"
)

// TestIbcComposabilityMwContractStore tests the setting and getting of the contract
// TestIbcComposabilityMwContractStore tests the setting and getting of the contract.
func TestIbcComposabilityMwContractStore(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

// TestExecuteGatewayGovernanceVaaUpgrades tests creating and cancelling upgrades
// TestExecuteGatewayGovernanceVaaUpgrades tests creating and cancelling upgrades.
func TestExecuteGatewayGovernanceVaaUpgrades(t *testing.T) {
_, ctx, msgServer, privateKeys, signer, guardianSet := setupWormholeMessageServer(t)

Expand Down Expand Up @@ -51,12 +51,12 @@ func TestExecuteGatewayGovernanceVaaUpgrades(t *testing.T) {
require.NotNil(t, res)
}

// TestExecuteGatewayGovernanceVaaSetIbcComposabilityMwContract tests setting the IBC composability contract
// TestExecuteGatewayGovernanceVaaSetIbcComposabilityMwContract tests setting the IBC composability contract.
func TestExecuteGatewayGovernanceVaaSetIbcComposabilityMwContract(t *testing.T) {
k, ctx, msgServer, privateKeys, signer, guardianSet := setupWormholeMessageServer(t)

// Get contract bytes
contractAddr := "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh"
contractAddr := WormholeContractAddress1
contractAddrBz, err := sdk.AccAddressFromBech32(contractAddr)
require.NoError(t, err)

Expand Down Expand Up @@ -84,7 +84,7 @@ func TestExecuteGatewayGovernanceVaaSetIbcComposabilityMwContract(t *testing.T)
require.Equal(t, contractAddr, contract.ContractAddress)
}

// TestExecuteGatewayGovernanceVaaUnknownAction tests submitting an unknown action
// TestExecuteGatewayGovernanceVaaUnknownAction tests submitting an unknown action.
func TestExecuteGatewayGovernanceVaaUnknownAction(t *testing.T) {
_, ctx, msgServer, privateKeys, signer, guardianSet := setupWormholeMessageServer(t)

Expand All @@ -105,7 +105,7 @@ func TestExecuteGatewayGovernanceVaaUnknownAction(t *testing.T) {
require.Error(t, err)
}

// TestExecuteGatewayGovernanceVaaInvalidVAA tests submitting an invalid VAA
// TestExecuteGatewayGovernanceVaaInvalidVAA tests submitting an invalid VAA.
func TestExecuteGatewayGovernanceVaaInvalidVAA(t *testing.T) {
_, ctx, msgServer, _, signer, guardianSet := setupWormholeMessageServer(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

// TestPostMessageProposal tests possible scenarios for how a governance wormhole message proposal can be handled
// TestPostMessageProposal tests possible scenarios for how a governance wormhole message proposal can be handled.
func TestPostMessageProposal(t *testing.T) {
// get app & ctx
app, ctx := keepertest.SetupWormchainAndContext(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

// TestGuardianSetUpdateProposal tests possible scenarios for how a guardian set update proposal can be handled
// TestGuardianSetUpdateProposal tests possible scenarios for how a guardian set update proposal can be handled.
func TestGuardianSetUpdateProposal(t *testing.T) {
// get app & ctx
app, ctx := keepertest.SetupWormchainAndContext(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

const (
WormholeContractAddress1 = "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh"
WormholeContractAddress2 = "wormhole1qg5ega6dykkxc307y25pecuufrjkxkaggkkxh7nad0vhyhtuhw3svg697z"
)

// setupWormholeMessageServer creates a keeper, context, msg server, private keys, signer, and guardian set for
// testing the wasm allowlist msg server
// testing the wasm allowlist msg server.
func setupWormholeMessageServer(t *testing.T) (keeper.Keeper, sdk.Context, types.MsgServer, []*ecdsa.PrivateKey, sdk.AccAddress, *types.GuardianSet) {
k, ctx := keepertest.WormholeKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
Expand All @@ -34,11 +39,11 @@ func setupWormholeMessageServer(t *testing.T) (keeper.Keeper, sdk.Context, types
return *k, ctx, msgServer, privateKeys, signer, guardianSet
}

// TestWasmAllowlistMsgServer tests the endpoints of the wasm allowlist msg server (happy path)
// TestWasmAllowlistMsgServer tests the endpoints of the wasm allowlist msg server (happy path).
func TestWasmAllowlistMsgServer(t *testing.T) {
k, ctx, msgServer, privateKeys, signer, guardianSet := setupWormholeMessageServer(t)

bech32ContractAddr := "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh"
bech32ContractAddr := WormholeContractAddress1

codeId := uint64(1)
contractAddr, err := sdk.AccAddressFromBech32(bech32ContractAddr)
Expand Down Expand Up @@ -98,11 +103,11 @@ func TestWasmAllowlistMsgServer(t *testing.T) {
}

// TestWasmAllowlistMsgServerMismatchedCodeId tests the endpoints of the wasm allowlist msg server
// with mismatched code id
// with mismatched code id.
func TestWasmAllowlistMsgServerMismatchedCodeId(t *testing.T) {
_, ctx, msgServer, privateKeys, signer, guardianSet := setupWormholeMessageServer(t)

bech32ContractAddr := "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh"
bech32ContractAddr := WormholeContractAddress1
codeId := uint64(1)

contractAddr, err := sdk.AccAddressFromBech32(bech32ContractAddr)
Expand Down Expand Up @@ -133,14 +138,14 @@ func TestWasmAllowlistMsgServerMismatchedCodeId(t *testing.T) {
}

// TestWasmAllowlistMsgServerMismatchedContractAddr tests the endpoints of the wasm allowlist msg server
// with mismatched contract addresses
// with mismatched contract addresses.
func TestWasmAllowlistMsgServerMismatchedContractAddr(t *testing.T) {
_, ctx, msgServer, privateKeys, signer, guardianSet := setupWormholeMessageServer(t)

bech32ContractAddr := "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh"
bech32ContractAddr := WormholeContractAddress1
codeId := uint64(1)

contractAddr2, err := sdk.AccAddressFromBech32("wormhole1qg5ega6dykkxc307y25pecuufrjkxkaggkkxh7nad0vhyhtuhw3svg697z")
contractAddr2, err := sdk.AccAddressFromBech32(WormholeContractAddress2)
require.NoError(t, err)

// Create payload with mismatched contract address
Expand All @@ -164,11 +169,11 @@ func TestWasmAllowlistMsgServerMismatchedContractAddr(t *testing.T) {
}

// TestWasmAllowlistMsgServerMismatchedVaaAction tests the endpoints of the wasm allowlist msg server
// with mismatched vaa action
// with mismatched vaa action.
func TestWasmAllowlistMsgServerMismatchedVaaAction(t *testing.T) {
_, ctx, msgServer, privateKeys, signer, guardianSet := setupWormholeMessageServer(t)

bech32ContractAddr := "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh"
bech32ContractAddr := WormholeContractAddress1
codeId := uint64(1)

contractAddr, err := sdk.AccAddressFromBech32(bech32ContractAddr)
Expand All @@ -195,11 +200,11 @@ func TestWasmAllowlistMsgServerMismatchedVaaAction(t *testing.T) {
}

// TestWasmAllowlistMsgServerInvalidVAA tests the endpoints of the wasm allowlist msg server
// with invalid vaa
// with invalid vaa.
func TestWasmAllowlistMsgServerInvalidVAA(t *testing.T) {
_, ctx, msgServer, _, signer, guardianSet := setupWormholeMessageServer(t)

bech32ContractAddr := "wormhole1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjq4lyjmh"
bech32ContractAddr := WormholeContractAddress1
codeId := uint64(1)

contractAddr, err := sdk.AccAddressFromBech32(bech32ContractAddr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/wormhole-foundation/wormchain/x/wormhole/types"
)

// TestWasmInstantiateAllowlist tests the setting, getting, and removing of allowed addresses
// TestWasmInstantiateAllowlist tests the setting, getting, and removing of allowed addresses.
func TestWasmInstantiateAllowlist(t *testing.T) {
k, ctx := keepertest.WormholeKeeper(t)

// Create entry
entry := types.WasmInstantiateAllowedContractCodeId{
ContractAddress: "wormhole1du4amsmvx8yqr8whw7qc5m3c0zpwknmzelwqy6",
ContractAddress: WormholeContractAddress1,
CodeId: 1,
}

Expand Down

0 comments on commit 24eb4bd

Please sign in to comment.