Skip to content

Commit

Permalink
validate bridge config before update
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Apr 2, 2024
1 parent db30bbf commit a76437e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
4 changes: 4 additions & 0 deletions x/ophost/keeper/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Check warning on line 22 in x/ophost/keeper/bridge.go

View check run for this annotation

Codecov / codecov/patch

x/ophost/keeper/bridge.go#L21-L22

Added lines #L21 - L22 were not covered by tests

return k.BridgeConfigs.Set(ctx, bridgeId, bridgeConfig)
}

Expand Down
8 changes: 4 additions & 4 deletions x/ophost/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
28 changes: 16 additions & 12 deletions x/ophost/keeper/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions x/ophost/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a76437e

Please sign in to comment.