Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.next1' into relayed-v3-integration-and-multi-tr…
Browse files Browse the repository at this point in the history
…ansfer
  • Loading branch information
miiu96 authored Jul 16, 2024
2 parents 643032a + 51838a7 commit 6ec7a77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
12 changes: 10 additions & 2 deletions process/elasticproc/logsevents/delegatorsProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const (
withdrawFunc = "withdraw"
reDelegateRewardsFunc = "reDelegateRewards"
claimRewardsFunc = "claimRewards"

minNumTopicsClaimRewards = 2
numTopicsClaimRewardsWithContractAddress = 3
)

type delegatorsProc struct {
Expand Down Expand Up @@ -137,18 +140,23 @@ func (dp *delegatorsProc) getDelegatorFromClaimRewardsEvent(args *argsProcessEve
// topics slice contains:
// topics[0] -- claimed rewards
// topics[1] -- true = if delegator was deleted
// topics[2] -- if is present will contain the contract address

if len(topics) < 2 {
if len(topics) < minNumTopicsClaimRewards {
return nil
}

shouldDelete := bytesToBool(topics[1])
shouldDelete := bytesToBool(topics[minNumTopicsClaimRewards-1])
if !shouldDelete {
return nil
}

encodedAddr := dp.pubkeyConverter.SilentEncode(args.event.GetAddress(), log)

encodedContractAddr := dp.pubkeyConverter.SilentEncode(args.logAddress, log)
if len(topics) == numTopicsClaimRewardsWithContractAddress {
encodedContractAddr = dp.pubkeyConverter.SilentEncode(topics[numTopicsClaimRewardsWithContractAddress-1], log)
}

return &data.Delegator{
Address: encodedAddr,
Expand Down
29 changes: 29 additions & 0 deletions process/elasticproc/logsevents/delegatorsProcessor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logsevents

import (
"encoding/hex"
"math/big"
"strconv"
"testing"
Expand Down Expand Up @@ -100,6 +101,34 @@ func TestDelegatorProcessor_ClaimRewardsWithDelete(t *testing.T) {
}, res.delegator)
}

func TestDelegatorProcessor_ClaimRewardsContractAddressInTopics(t *testing.T) {
t.Parallel()

contractAddress := []byte("contract2")
event := &transaction.Event{
Address: []byte("addr"),
Identifier: []byte(claimRewardsFunc),
Topics: [][]byte{big.NewInt(1000).Bytes(), []byte(strconv.FormatBool(true)), contractAddress},
}
args := &argsProcessEvent{
timestamp: 1234,
event: event,
logAddress: []byte("contract1"),
selfShardID: core.MetachainShardId,
}

balanceConverter, _ := converters.NewBalanceConverter(10)
delegatorsProcessor := newDelegatorsProcessor(&mock.PubkeyConverterMock{}, balanceConverter)

res := delegatorsProcessor.processEvent(args)
require.True(t, res.processed)
require.Equal(t, &data.Delegator{
Address: "61646472",
Contract: hex.EncodeToString(contractAddress),
ShouldDelete: true,
}, res.delegator)
}

func TestDelegatorProcessor_ClaimRewardsNoDelete(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 6ec7a77

Please sign in to comment.