Skip to content

Commit

Permalink
fixup! feat(evm-reader): Read claim acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Sep 5, 2024
1 parent 92a0535 commit 9d5b564
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
5 changes: 2 additions & 3 deletions internal/evmreader/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ func (r *EvmReader) readAndUpdateClaims(
appAddresses := appToAddresses(apps)

// All these apps shares the same IConsensus
if len(apps) == 0 {
continue
}
// If there is a key on indexApps, there is at least one
// application in the referred application slice
consensusContract := apps[0].consensusContract

// Retrieve Claim Acceptance Events from blockchain
Expand Down
89 changes: 89 additions & 0 deletions internal/evmreader/evmreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,95 @@ func newMockRepository() *MockRepository {

}

func (s *EvmReaderSuite) TestIndexApps() {

s.Run("Ok", func() {
apps := []application{
{Application: Application{LastProcessedBlock: 23}},
{Application: Application{LastProcessedBlock: 22}},
{Application: Application{LastProcessedBlock: 21}},
{Application: Application{LastProcessedBlock: 23}},
}

keyByProcessedBlock := func(a application) uint64 {
return a.LastProcessedBlock
}

indexApps := indexApps(keyByProcessedBlock, apps)

s.Require().Equal(3, len(indexApps))
apps, ok := indexApps[23]
s.Require().True(ok)
s.Require().Equal(2, len(apps))
})

s.Run("whenIndexAppsArrayEmpty", func() {
apps := []application{}

keyByProcessedBlock := func(a application) uint64 {
return a.LastProcessedBlock
}

indexApps := indexApps(keyByProcessedBlock, apps)

s.Require().Equal(0, len(indexApps))
})

s.Run("whenIndexAppsArray", func() {
apps := []application{}

keyByProcessedBlock := func(a application) uint64 {
return a.LastProcessedBlock
}

indexApps := indexApps(keyByProcessedBlock, apps)

s.Require().Equal(0, len(indexApps))
})

s.Run("whenIndexByEmptyKey", func() {
apps := []application{
{Application: Application{LastProcessedBlock: 23}},
{Application: Application{LastProcessedBlock: 22}},
{Application: Application{LastProcessedBlock: 21}},
{Application: Application{LastProcessedBlock: 23}},
}

keyByIConsensus := func(a application) ConsensusContract {
return a.consensusContract
}

indexApps := indexApps(keyByIConsensus, apps)

s.Require().Equal(1, len(indexApps))
apps, ok := indexApps[nil]
s.Require().True(ok)
s.Require().Equal(4, len(apps))
})

s.Run("whenUsesWrongKey", func() {
apps := []application{
{Application: Application{LastProcessedBlock: 23}},
{Application: Application{LastProcessedBlock: 22}},
{Application: Application{LastProcessedBlock: 21}},
{Application: Application{LastProcessedBlock: 23}},
}

keyByProcessedBlock := func(a application) uint64 {
return a.LastProcessedBlock
}

indexApps := indexApps(keyByProcessedBlock, apps)

s.Require().Equal(3, len(indexApps))
apps, ok := indexApps[0]
s.Require().False(ok)
s.Require().Nil(apps)

})

}

func (m *MockRepository) Unset(methodName string) {
for _, call := range m.ExpectedCalls {
if call.Method == methodName {
Expand Down

0 comments on commit 9d5b564

Please sign in to comment.