From a76437e69f90b59381473a6edf1a6bd0157fcafb Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:28:08 +0900 Subject: [PATCH] validate bridge config before update --- x/ophost/keeper/bridge.go | 4 ++++ x/ophost/keeper/genesis_test.go | 8 ++++---- x/ophost/keeper/output_test.go | 28 ++++++++++++++++------------ x/ophost/keeper/querier_test.go | 14 ++++++++------ 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/x/ophost/keeper/bridge.go b/x/ophost/keeper/bridge.go index 3ac7061c..08fcde11 100644 --- a/x/ophost/keeper/bridge.go +++ b/x/ophost/keeper/bridge.go @@ -17,6 +17,10 @@ func (k Keeper) SetBridgeConfig( bridgeId uint64, bridgeConfig types.BridgeConfig, ) error { + if err := bridgeConfig.Validate(k.authKeeper.AddressCodec()); err != nil { + return err + } + return k.BridgeConfigs.Set(ctx, bridgeId, bridgeConfig) } diff --git a/x/ophost/keeper/genesis_test.go b/x/ophost/keeper/genesis_test.go index 6d92c8b3..fa364aae 100644 --- a/x/ophost/keeper/genesis_test.go +++ b/x/ophost/keeper/genesis_test.go @@ -13,16 +13,16 @@ func Test_GenesisImportExport(t *testing.T) { params := input.OPHostKeeper.GetParams(ctx) config1 := types.BridgeConfig{ - Challenger: "challenger", - Proposer: "proposer", + Challenger: addrsStr[1], + Proposer: addrsStr[0], SubmissionInterval: 100, FinalizationPeriod: 100, SubmissionStartTime: time.Now().UTC(), Metadata: []byte{1, 2, 3}, } config2 := types.BridgeConfig{ - Challenger: "challenger2", - Proposer: "proposer2", + Challenger: addrsStr[2], + Proposer: addrsStr[3], SubmissionInterval: 200, FinalizationPeriod: 200, SubmissionStartTime: time.Now().UTC(), diff --git a/x/ophost/keeper/output_test.go b/x/ophost/keeper/output_test.go index 24c88636..9e9b6e44 100644 --- a/x/ophost/keeper/output_test.go +++ b/x/ophost/keeper/output_test.go @@ -79,15 +79,17 @@ func Test_IterateOutputProposal(t *testing.T) { func Test_IsFinalized(t *testing.T) { ctx, input := createDefaultTestInput(t) - input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{ - Challenger: "", - Proposer: "", - SubmissionInterval: 100, - FinalizationPeriod: time.Second * 10, + err := input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{ + Challenger: addrsStr[1], + Proposer: addrsStr[0], + SubmissionInterval: 100, + FinalizationPeriod: time.Second * 10, + SubmissionStartTime: time.Now().UTC(), }) + require.NoError(t, err) proposeTime := time.Now().UTC() - err := input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{ + err = input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{ OutputRoot: []byte{1, 2, 3}, L1BlockTime: proposeTime, L2BlockNumber: 100, @@ -134,15 +136,17 @@ func Test_NextOutputIndex(t *testing.T) { func Test_GetLastFinalizedOutput(t *testing.T) { ctx, input := createDefaultTestInput(t) - input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{ - Challenger: "", - Proposer: "", - SubmissionInterval: 100, - FinalizationPeriod: time.Second * 10, + err := input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{ + Proposer: addrsStr[0], + Challenger: addrsStr[1], + SubmissionInterval: 100, + FinalizationPeriod: time.Second * 10, + SubmissionStartTime: time.Now().UTC(), }) + require.NoError(t, err) proposeTime := time.Now().UTC() - err := input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{ + err = input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{ OutputRoot: []byte{1, 2, 3}, L1BlockTime: proposeTime, L2BlockNumber: 100, diff --git a/x/ophost/keeper/querier_test.go b/x/ophost/keeper/querier_test.go index a306d3d5..7577faae 100644 --- a/x/ophost/keeper/querier_test.go +++ b/x/ophost/keeper/querier_test.go @@ -177,15 +177,17 @@ func Test_QueryOutputProposals(t *testing.T) { func Test_QueryLastFinalizedOutput(t *testing.T) { ctx, input := createDefaultTestInput(t) - input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{ - Challenger: "", - Proposer: "", - SubmissionInterval: 100, - FinalizationPeriod: time.Second * 10, + err := input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{ + Proposer: addrsStr[0], + Challenger: addrsStr[1], + SubmissionInterval: 100, + FinalizationPeriod: time.Second * 10, + SubmissionStartTime: time.Now().UTC(), }) + require.NoError(t, err) proposeTime := time.Now().UTC() - err := input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{ + err = input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, types.Output{ OutputRoot: []byte{1, 2, 3}, L1BlockTime: proposeTime, L2BlockNumber: 100,