Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 39 additions & 44 deletions internal/claimer/claimer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository/repotest"
"github.com/cartesi/rollups-node/pkg/contracts/iconsensus"
"github.com/cartesi/rollups-node/pkg/service"
"github.com/lmittmann/tint"
Expand Down Expand Up @@ -198,28 +199,22 @@ func newServiceMock() (*Service, *claimerRepositoryMock, *claimerBlockchainMock)
return claimer, repository, blockchain
}

func makeApplication(id int64) *model.Application {
return &model.Application{
ID: id,
IApplicationAddress: common.HexToAddress("0x01"),
IConsensusAddress: common.HexToAddress("0x01"),
IInputBoxAddress: common.HexToAddress("0x02"),
}
func makeApplication() *model.Application {
return repotest.NewApplicationBuilder().
WithEpochLength(10).
Build()
}

func makeEpoch(id int64, status model.EpochStatus, i uint64) *model.Epoch {
hash := common.HexToHash("0x01")
tx := common.HexToHash("0x02")
epoch := &model.Epoch{
ApplicationID: id,
Index: i,
FirstBlock: i * 10,
LastBlock: i*10 + 9,
Status: status,
ClaimTransactionHash: &tx,
OutputsMerkleRoot: &hash,
}
return epoch
outputsMerkleRoot := common.HexToHash("0x01") // dummy value
txHash := common.HexToHash("0x02") // dummy value
return repotest.NewEpochBuilder(id).
WithIndex(i).
WithBlocks(i * 10, i * 10 + 9).
WithStatus(status).
WithClaimTransactionHash(txHash).
WithOutputsMerkleRoot(outputsMerkleRoot).
Build()
}

func makeAcceptedEpoch(app *model.Application, i uint64) *model.Epoch {
Expand Down Expand Up @@ -292,7 +287,7 @@ func TestSubmitFirstClaim(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(40)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 3)
var prevEvent *iconsensus.IConsensusClaimSubmitted = nil
var currEvent *iconsensus.IConsensusClaimSubmitted = nil
Expand All @@ -315,7 +310,7 @@ func TestSubmitClaimWithAntecessor(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 3)
var currEvent *iconsensus.IConsensusClaimSubmitted = nil
Expand All @@ -340,7 +335,7 @@ func TestSkipSubmitFirstClaim(t *testing.T) {

m.submissionEnabled = false
endBlock := big.NewInt(40)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 3)
var prevEvent *iconsensus.IConsensusClaimSubmitted = nil
var currEvent *iconsensus.IConsensusClaimSubmitted = nil
Expand All @@ -362,7 +357,7 @@ func TestSkipSubmitClaimWithAntecessor(t *testing.T) {

m.submissionEnabled = false
endBlock := big.NewInt(40)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 3)
prevEvent := makeSubmittedEvent(app, prevEpoch)
Expand All @@ -385,7 +380,7 @@ func TestInFlightCompleted(t *testing.T) {

txHash := common.HexToHash("0x10")
endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 3)
currEpoch.ClaimTransactionHash = &txHash

Expand Down Expand Up @@ -413,7 +408,7 @@ func TestInFlightReverted(t *testing.T) {

txHash := common.HexToHash("0x10")
endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 3)
currEpoch.ClaimTransactionHash = &txHash

Expand Down Expand Up @@ -447,7 +442,7 @@ func TestUpdateFirstClaim(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(40)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 3)
var prevEvent *iconsensus.IConsensusClaimSubmitted = nil
currEvent := makeSubmittedEvent(app, currEpoch)
Expand All @@ -470,7 +465,7 @@ func TestUpdateClaimWithAntecessor(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 3)
prevEvent := makeSubmittedEvent(app, prevEpoch)
Expand All @@ -494,7 +489,7 @@ func TestAcceptFirstClaim(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeSubmittedEpoch(app, 3)
var prevEvent *iconsensus.IConsensusClaimAccepted = nil
currEvent := makeAcceptedEvent(app, currEpoch)
Expand All @@ -514,7 +509,7 @@ func TestAcceptClaimWithAntecessor(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeSubmittedEpoch(app, 3)
prevEvent := makeAcceptedEvent(app, prevEpoch)
Expand Down Expand Up @@ -544,7 +539,7 @@ func TestClaimInFlightMissingFromCurrClaims(t *testing.T) {
reqHash := common.HexToHash("0x01")
receipt := new(types.Receipt)

app := makeApplication(0)
app := makeApplication()
m.claimsInFlight[app.ID] = reqHash

b.On("pollTransaction", mock.Anything, reqHash, endBlock).
Expand All @@ -565,7 +560,7 @@ func TestSubmitFailedClaim(t *testing.T) {
reqHash := common.HexToHash("0x01")
var nilReceipt *types.Receipt

app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 3)
prevEvent := makeSubmittedEvent(app, prevEpoch)
Expand Down Expand Up @@ -593,7 +588,7 @@ func TestSubmitClaimWithAntecessorMismatch(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 3)

Expand Down Expand Up @@ -625,7 +620,7 @@ func TestSubmitClaimWithEventMismatch(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(40)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 3)
prevEvent := makeSubmittedEvent(app, prevEpoch)
Expand All @@ -648,7 +643,7 @@ func TestSubmitClaimWithAntecessorOutOfOrder(t *testing.T) {
defer r.AssertExpectations(t)
defer b.AssertExpectations(t)

app := makeApplication(0)
app := makeApplication()
prevEpoch := makeSubmittedEpoch(app, 2)
currEpoch := makeComputedEpoch(app, 1)

Expand All @@ -667,7 +662,7 @@ func TestErrSubmittedMissingEvent(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeComputedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 2)
var prevEvent *iconsensus.IConsensusClaimSubmitted = nil
Expand All @@ -690,7 +685,7 @@ func TestConsensusAddressChangedOnSubmittedClaims(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 3)
wrongConsensusAddress := app.IConsensusAddress
wrongConsensusAddress[0]++
Expand All @@ -715,7 +710,7 @@ func TestFindClaimAcceptedEventAndSuccFailure0(t *testing.T) {
expectedErr := fmt.Errorf("not found")
endBlock := big.NewInt(100)

app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 2)
var prevEvent *iconsensus.IConsensusClaimAccepted = nil
currEvent := makeAcceptedEvent(app, currEpoch)
Expand All @@ -737,7 +732,7 @@ func TestFindClaimAcceptedEventAndSuccFailure1(t *testing.T) {
expectedErr := fmt.Errorf("not found")
endBlock := big.NewInt(100)

app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 2)
prevEvent := makeAcceptedEvent(app, prevEpoch)
Expand All @@ -759,7 +754,7 @@ func TestAcceptClaimWithAntecessorMismatch(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 3)

Expand Down Expand Up @@ -788,7 +783,7 @@ func TestAcceptClaimWithEventMismatch(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeAcceptedEpoch(app, 1)
wrongEpoch := makeComputedEpoch(app, 2)
currEpoch := makeComputedEpoch(app, 3)
Expand All @@ -812,7 +807,7 @@ func TestAcceptClaimWithAntecessorOutOfOrder(t *testing.T) {
defer r.AssertExpectations(t)
defer b.AssertExpectations(t)

app := makeApplication(0)
app := makeApplication()
wrongEpoch := makeComputedEpoch(app, 2)
currEpoch := makeComputedEpoch(app, 1)

Expand All @@ -832,7 +827,7 @@ func TestErrAcceptedMissingEvent(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeComputedEpoch(app, 1)
currEpoch := makeComputedEpoch(app, 2)
var prevEvent *iconsensus.IConsensusClaimAccepted = nil
Expand All @@ -857,7 +852,7 @@ func TestUpdateEpochWithAcceptedClaimFailed(t *testing.T) {
expectedErr := fmt.Errorf("not found")

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
prevEpoch := makeSubmittedEpoch(app, 1)
currEpoch := makeSubmittedEpoch(app, 2)
prevEvent := makeAcceptedEvent(app, prevEpoch)
Expand All @@ -880,7 +875,7 @@ func TestConsensusAddressChangedOnAcceptedClaims(t *testing.T) {
defer b.AssertExpectations(t)

endBlock := big.NewInt(100)
app := makeApplication(0)
app := makeApplication()
currEpoch := makeComputedEpoch(app, 3)
wrongConsensusAddress := app.IConsensusAddress
wrongConsensusAddress[0]++
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/repotest/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (b *EpochBuilder) WithInputBounds(lower, upper uint64) *EpochBuilder {
return b
}

func (b *EpochBuilder) WithClaimHash(h common.Hash) *EpochBuilder {
func (b *EpochBuilder) WithOutputsMerkleRoot(h common.Hash) *EpochBuilder {
b.epoch.OutputsMerkleRoot = &h
return b
}
Expand Down
Loading