Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Mar 25, 2024
1 parent b5f8449 commit 6062b27
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions x/ophost/keeper/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func (k Keeper) DeleteOutputProposal(ctx context.Context, bridgeId, outputIndex
if err != nil {
return err
}
if isFinal, err := k.isFinalized(ctx, bridgeId, output); err != nil {
if isFinalized, err := k.isFinalized(ctx, bridgeId, output); err != nil {
return err
} else if isFinal {
} else if isFinalized {
return types.ErrAlreadyFinalized
}

Expand Down
30 changes: 30 additions & 0 deletions x/ophost/keeper/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,33 @@ func Test_NextOutputIndex(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(101), index)
}

func Test_DeleteOutputProposal(t *testing.T) {
ctx, input := createDefaultTestInput(t)

output := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockTime: ctx.BlockTime(),
L2BlockNumber: 100,
}
err := input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, output)
require.NoError(t, err)

err = input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{
Challenger: "",
Proposer: "",
SubmissionInterval: time.Second * 10,
FinalizationPeriod: time.Second * 10,
SubmissionStartTime: ctx.BlockTime(),
Metadata: nil,
})
require.NoError(t, err)

// delete should fail due to already finalized error
err = input.OPHostKeeper.DeleteOutputProposal(ctx.WithBlockTime(ctx.BlockTime().Add(time.Second*11)), 1, 1)
require.ErrorIs(t, err, types.ErrAlreadyFinalized)

// delete should success
err = input.OPHostKeeper.DeleteOutputProposal(ctx.WithBlockTime(ctx.BlockTime().Add(time.Second*9)), 1, 1)
require.NoError(t, err)
}

0 comments on commit 6062b27

Please sign in to comment.