Skip to content

Commit

Permalink
fixup! feat(evm-reader): Add evm-reader tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Jul 19, 2024
1 parent 2a8499e commit 440d586
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions internal/evmreader/evmreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,114 @@ func (s *EvmReaderSuite) TestItReadsInputsFromNewBlocks() {
)
}

func (s *EvmReaderSuite) TestItUpdatesLastProcessedBlockWhenThereIsNoInputs() {

waitGroup := sync.WaitGroup{}
wsClient := FakeWSEhtClient{}
wsClient.NewHeaders = []*Header{&header0, &header1}
wsClient.WaitGroup = &waitGroup
inputReader := NewEvmReader(
s.client,
&wsClient,
s.inputBox,
s.repository,
model.NodePersistentConfig{
InputBoxDeploymentBlock: 0x10,
DefaultBlock: model.DefaultBlockStatusLatest,
},
)

// Prepare repository
s.repository.Unset("GetAllRunningApplications")
s.repository.On(
"GetAllRunningApplications",
mock.Anything,
).Return([]Application{{
ContractAddress: common.HexToAddress("0x2E663fe9aE92275242406A185AA4fC8174339D3E"),
LastProcessedBlock: 0x00,
}}, nil).Once()
s.repository.On(
"GetAllRunningApplications",
mock.Anything,
).Return([]Application{{
ContractAddress: common.HexToAddress("0x2E663fe9aE92275242406A185AA4fC8174339D3E"),
LastProcessedBlock: 0x11,
}}, nil).Once()

// Prepare Client
s.client.Unset("HeaderByNumber")
s.client.On(
"HeaderByNumber",
mock.Anything,
mock.Anything,
).Return(&header0, nil).Once()
s.client.On(
"HeaderByNumber",
mock.Anything,
mock.Anything,
).Return(&header1, nil).Once()
s.client.On(
"HeaderByNumber",
mock.Anything,
mock.Anything,
).Return(&header2, nil).Once()

// Prepare sequence of inputs
s.inputBox.Unset("RetrieveInputs")
events_0 := []InputBoxInputAdded{}
currentMostRecentFinalizedBlockNumber_0 := uint64(0x11)
retrieveInputsOpts_0 := bind.FilterOpts{
Context: s.ctx,
Start: 0x10,
End: &currentMostRecentFinalizedBlockNumber_0,
}
s.inputBox.On(
"RetrieveInputs",
&retrieveInputsOpts_0,
mock.Anything,
mock.Anything,
).Return(events_0, nil)

events_1 := []InputBoxInputAdded{}
currentMostRecentFinalizedBlockNumber_1 := uint64(0x12)
retrieveInputsOpts_1 := bind.FilterOpts{
Context: s.ctx,
Start: 0x12,
End: &currentMostRecentFinalizedBlockNumber_1,
}
s.inputBox.On(
"RetrieveInputs",
&retrieveInputsOpts_1,
mock.Anything,
mock.Anything,
).Return(events_1, nil)

// Start service
ready := make(chan struct{}, 1)
errChannel := make(chan error, 1)

waitGroup.Add(1)
go func() {
errChannel <- inputReader.Run(s.ctx, ready)
}()

select {
case <-ready:
break
case err := <-errChannel:
s.FailNow("unexpected error signal", err)
}

waitGroup.Wait()

s.inputBox.AssertNumberOfCalls(s.T(), "RetrieveInputs", 2)
s.repository.AssertNumberOfCalls(
s.T(),
"InsertInputsAndUpdateLastProcessedBlock",
2,
)
}

func (s *EvmReaderSuite) TestItReadsMultipleInputsFromSingleNewBlock() {

waitGroup := sync.WaitGroup{}
Expand Down

0 comments on commit 440d586

Please sign in to comment.