Skip to content

Commit

Permalink
feat(data): add inputreader repository tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Jun 26, 2024
1 parent 2742b80 commit 049510f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions internal/repository/inputreader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

package repository

import (
. "github.com/cartesi/rollups-node/internal/node/model"
"github.com/ethereum/go-ethereum/common"
)

func (s *RepositorySuite) TestInsertInputsAndUpdateMostRecentFinalizedBlock() {
input1 := Input{
Index: 6,
Status: Accepted,
Blob: common.Hex2Bytes("deadbeef"),
BlockNumber: 5,
MachineStateHash: common.HexToHash("deadbeef"),
}

input2 := Input{
Index: 7,
Status: Accepted,
Blob: common.Hex2Bytes("deadbeef"),
BlockNumber: 5,
MachineStateHash: common.HexToHash("deadbeef"),
}

input3 := Input{
Index: 8,
Status: Accepted,
Blob: common.Hex2Bytes("deadbeef"),
BlockNumber: 5,
MachineStateHash: common.HexToHash("deadbeef"),
}

var inputs []*Input
inputs = append(inputs, &input1)
inputs = append(inputs, &input2)
inputs = append(inputs, &input3)

err := s.database.InsertInputsAndUpdateMostRecentlyFinalizedBlock(s.ctx, inputs, 5)
s.Require().Nil(err)

response, err := s.database.GetInput(s.ctx, 6)
s.Require().Nil(err)
s.Require().Equal(&input1, response)
}

func (s *RepositorySuite) TestInsertInputsAndUpdateMostRecentFinalizedBlockEmptyInputs() {
var inputs []*Input

err := s.database.InsertInputsAndUpdateMostRecentlyFinalizedBlock(s.ctx, inputs, 6)
s.Require().Nil(err)

var block uint64 = 6
response, err := s.database.GetMostRecentBlock(s.ctx)
s.Require().Nil(err)
s.Require().Equal(block, response)
}

0 comments on commit 049510f

Please sign in to comment.