Finish ICTs

This commit is contained in:
Joel Smith 2024-12-13 16:41:07 -06:00
parent cac7841365
commit 8ef9a9ca0c
10 changed files with 113 additions and 37 deletions

View File

@ -6,7 +6,7 @@ release/
testing/js/node_modules
!build
build/wormhole-chaind
build/wormchaind
build/wormchaind*
build/data
devnet/wormchain-*/data
devnet/wormchain-*/config/*.toml

View File

@ -41,7 +41,7 @@ func SetMiddlewareContract(
}
payloadBz, err := payload.Serialize()
require.NoError(t, err)
v := generateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payloadBz)
v := GenerateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payloadBz)
vBz, err := v.Marshal()
require.NoError(t, err)
vHex := hex.EncodeToString(vBz)
@ -67,7 +67,7 @@ func ScheduleUpgrade(
}
payloadBz, err := payload.Serialize()
require.NoError(t, err)
v := generateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payloadBz)
v := GenerateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payloadBz)
vBz, err := v.Marshal()
require.NoError(t, err)
vHex := hex.EncodeToString(vBz)
@ -87,7 +87,7 @@ func CancelUpgrade(
payloadBz, err := vaa.EmptyPayloadVaa(vaa.GatewayModuleStr, vaa.ActionCancelUpgrade, vaa.ChainIDWormchain)
require.NoError(t, err)
v := generateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payloadBz)
v := GenerateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payloadBz)
vBz, err := v.Marshal()
require.NoError(t, err)
vHex := hex.EncodeToString(vBz)

View File

@ -39,7 +39,7 @@ func SubmitAllowlistInstantiateContract(
}
payloadBz, err := payload.Serialize(vaa.ActionAddWasmInstantiateAllowlist)
require.NoError(t, err)
v := generateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payloadBz)
v := GenerateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payloadBz)
vBz, err := v.Marshal()
require.NoError(t, err)
vHex := hex.EncodeToString(vBz)
@ -83,7 +83,7 @@ func SubmitUpdateChainToChannelMapMsg(t *testing.T, allowlistChainID uint16, all
payload.Write(channelPadded.Bytes())
vaa.MustWrite(payload, binary.BigEndian, allowlistChainID)
v := generateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payload.Bytes())
v := GenerateVaa(0, guardians, vaa.GovernanceChain, vaa.GovernanceEmitter, payload.Bytes())
vBz, err := v.Marshal()
require.NoError(t, err)
@ -162,7 +162,7 @@ func IbcTranslatorCompleteTransferAndConvertMsg(t *testing.T, emitterChainID uin
emitterBz[eIndex-1] = emitterAddr[i-1]
eIndex--
}
v := generateVaa(0, guardians, vaa.ChainID(emitterChainID), vaa.Address(emitterBz), payload)
v := GenerateVaa(0, guardians, vaa.ChainID(emitterChainID), vaa.Address(emitterBz), payload)
vBz, err := v.Marshal()
require.NoError(t, err)

View File

@ -47,7 +47,7 @@ func InstantiateContract(
code_id, err := strconv.ParseUint(codeId, 10, 64)
require.NoError(t, err)
payload := createWasmInstantiatePayload(code_id, label, message)
v := generateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
v := GenerateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
vBz, err := v.Marshal()
require.NoError(t, err)
vHex := hex.EncodeToString(vBz)

View File

@ -42,7 +42,7 @@ func MigrateContract(
code_id, err := strconv.ParseUint(codeId, 10, 64)
require.NoError(t, err)
payload := createWasmMigrationPayload(code_id, contractAddr, message)
v := generateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
v := GenerateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
vBz, err := v.Marshal()
require.NoError(t, err)
vHex := hex.EncodeToString(vBz)

View File

@ -79,7 +79,7 @@ func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain,
}
payload := createWasmStoreCodePayload(content)
v := generateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
v := GenerateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
vBz, err := v.Marshal()
require.NoError(t, err)

View File

@ -69,7 +69,7 @@ func TbRegisterChainMsg(t *testing.T, chainID uint16, emitterAddr string, guardi
payload, err := bodyTbRegisterChain.Serialize()
require.NoError(t, err)
v := generateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
v := GenerateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payload)
vBz, err := v.Marshal()
require.NoError(t, err)
@ -106,7 +106,7 @@ func TbRegisterForeignAsset(t *testing.T, tokenAddr string, chainID uint16, emit
emitterBz[eIndex-1] = emitterAddr[i-1]
eIndex--
}
v := generateVaa(0, guardians, vaa.ChainID(chainID), vaa.Address(emitterBz), payload.Bytes())
v := GenerateVaa(0, guardians, vaa.ChainID(chainID), vaa.Address(emitterBz), payload.Bytes())
vBz, err := v.Marshal()
require.NoError(t, err)

View File

@ -17,7 +17,7 @@ func signVaa(vaaToSign vaa.VAA, signers *guardians.ValSet) vaa.VAA {
return vaaToSign
}
func generateVaa(index uint32, signers *guardians.ValSet, emitterChain vaa.ChainID, emitterAddr vaa.Address, payload []byte) vaa.VAA {
func GenerateVaa(index uint32, signers *guardians.ValSet, emitterChain vaa.ChainID, emitterAddr vaa.Address, payload []byte) vaa.VAA {
v := vaa.VAA{
Version: uint8(1),
GuardianSetIndex: index,

View File

@ -73,7 +73,7 @@ func createSlashingParamsUpdate(
// querySlashingParams queries the slashing params from the chain
func querySlashingParams(ctx context.Context, wormchain *cosmos.CosmosChain) (params slashingtypes.Params, err error) {
// query the slashing params
res, _, err := wormchain.GetNode().ExecQuery(ctx, "slashing", "params")
res, _, err := wormchain.GetFullNode().ExecQuery(ctx, "slashing", "params")
if err != nil {
return
}
@ -112,6 +112,36 @@ func querySlashingParams(ctx context.Context, wormchain *cosmos.CosmosChain) (pa
return
}
// createAndExecuteVaa creates and executes a governance VAA on the wormchain
func createAndExecuteVaa(ctx context.Context, guardians *guardians.ValSet, wormchain *cosmos.CosmosChain, payloadBytes []byte) error {
v := helpers.GenerateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payloadBytes)
vBz, err := v.Marshal()
if err != nil {
return err
}
vHex := hex.EncodeToString(vBz)
_, err = wormchain.FullNodes[0].ExecTx(ctx, "faucet", "wormhole", "execute-governance-vaa", vHex)
if err != nil {
return err
}
return nil
}
func verifyParams(t *testing.T, ctx context.Context, wormchain *cosmos.CosmosChain) {
// query the slashing params
slashingParams, err := querySlashingParams(ctx, wormchain)
require.NoError(t, err)
// validate the slashing params did not change
require.Equal(t, int64(200), slashingParams.SignedBlocksWindow)
require.Equal(t, "0.100000000000000000", slashingParams.MinSignedPerWindow.String())
require.Equal(t, 300*time.Second, slashingParams.DowntimeJailDuration)
require.Equal(t, "0.200000000000000000", slashingParams.SlashFractionDoubleSign.String())
require.Equal(t, "0.300000000000000000", slashingParams.SlashFractionDowntime.String())
}
// TestSlashingParamsUpdateVaa tests the execution of a slashing params update VAA
// and verifies that the governance module correctly updates the slashing params
func TestSlashingParamsUpdateVaa(t *testing.T) {
@ -121,35 +151,80 @@ func TestSlashingParamsUpdateVaa(t *testing.T) {
t.Parallel()
// Base setup
// base setup
guardians := guardians.CreateValSet(t, 2)
chains := CreateLocalChain(t, *guardians)
ic, ctx, _, _, _, _ := BuildInterchain(t, chains)
require.NotNil(t, ic)
chains := CreateChains(t, "local", *guardians)
ctx, _, _, _ := BuildInterchain(t, chains)
require.NotNil(t, ctx)
wormchain := chains[0].(*cosmos.CosmosChain)
// Create a governance VAA
// ------------------------------
// create a governance VAA -- happy path
payloadBytes, err := createSlashingParamsUpdate(200, "0.1", 300, "0.2", "0.3")
require.NoError(t, err)
v := helpers.GenerateVaa(0, guardians, vaa.ChainID(vaa.GovernanceChain), vaa.Address(vaa.GovernanceEmitter), payloadBytes)
vBz, err := v.Marshal()
require.NoError(t, err)
vHex := hex.EncodeToString(vBz)
_, err = wormchain.FullNodes[0].ExecTx(ctx, "faucet", "wormhole", "execute-governance-vaa", vHex)
// create and send
err = createAndExecuteVaa(ctx, guardians, wormchain, payloadBytes)
require.NoError(t, err)
// query the slashing params
slashingParams, err := querySlashingParams(ctx, wormchain)
// verify the slashing params
verifyParams(t, ctx, wormchain)
// ------------------------------
// create a governance VAA - invalid signed blocks window
payloadBytes, err = createSlashingParamsUpdate(0, "0.1", 300, "0.2", "0.3")
require.NoError(t, err)
// validate the slashing params changed
require.Equal(t, int64(200), slashingParams.SignedBlocksWindow)
require.Equal(t, "0.100000000000000000", slashingParams.MinSignedPerWindow.String())
require.Equal(t, 300*time.Second, slashingParams.DowntimeJailDuration)
require.Equal(t, "0.200000000000000000", slashingParams.SlashFractionDoubleSign.String())
require.Equal(t, "0.300000000000000000", slashingParams.SlashFractionDowntime.String())
// create and send
err = createAndExecuteVaa(ctx, guardians, wormchain, payloadBytes)
// TODO: ON COSMOS SDK V0.47 - WILL ERROR
require.NoError(t, err)
// verify the slashing params
verifyParams(t, ctx, wormchain)
// ------------------------------
// create a governance VAA - invalid downtime jail duration
payloadBytes, err = createSlashingParamsUpdate(200, "0.1", 0, "0.2", "0.3")
require.NoError(t, err)
// create and send
err = createAndExecuteVaa(ctx, guardians, wormchain, payloadBytes)
// TODO: ON COSMOS SDK V0.47 - WILL ERROR
require.NoError(t, err)
// verify the slashing params
verifyParams(t, ctx, wormchain)
// ------------------------------
// create a governance VAA - invalid slash fraction double sign
payloadBytes, err = createSlashingParamsUpdate(200, "0.1", 300, "2.0", "0.3")
require.NoError(t, err)
// create and send
err = createAndExecuteVaa(ctx, guardians, wormchain, payloadBytes)
// TODO: ON COSMOS SDK V0.47 - WILL ERROR
require.NoError(t, err)
// verify the slashing params
verifyParams(t, ctx, wormchain)
// ------------------------------
// create a governance VAA - invalid slash fraction downtime
payloadBytes, err = createSlashingParamsUpdate(200, "0.1", 300, "0.2", "2.0")
require.NoError(t, err)
// create and send
err = createAndExecuteVaa(ctx, guardians, wormchain, payloadBytes)
// TODO: ON COSMOS SDK V0.47 - WILL ERROR
require.NoError(t, err)
// verify the slashing params
verifyParams(t, ctx, wormchain)
}

View File

@ -83,10 +83,11 @@ func (k msgServer) ExecuteGovernanceVAA(goCtx context.Context, msg *types.MsgExe
)
// Set the new params
err := k.slashingKeeper.SetParams(ctx, params)
if err != nil {
return nil, err
}
//
// TODO: Once upgraded to CosmosSDK v0.47, this method will return an error
// if the params do not pass validation checks. Because of that, we need to
// return the error from this function.
k.slashingKeeper.SetParams(ctx, params)
default:
return nil, types.ErrUnknownGovernanceAction