Skip to content

Commit

Permalink
Merge pull request #1101 from maticnetwork/v1.0.3-candidate
Browse files Browse the repository at this point in the history
Merge V1.0.3 candidate to master
  • Loading branch information
Raneet10 authored Nov 3, 2023
2 parents 8811f35 + cb7aa51 commit 1842793
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 10 deletions.
6 changes: 6 additions & 0 deletions helper/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ var (

// UnpackLog unpacks log
func UnpackLog(abiObject *abi.ABI, out interface{}, event string, log *types.Log) error {
selectedEvent := EventByID(abiObject, log.Topics[0].Bytes())

if selectedEvent == nil || selectedEvent.Name != event {
return errors.New("topic event mismatch")
}

if len(log.Data) > 0 {
if err := abiObject.UnpackIntoInterface(out, event, log.Data); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions packaging/deb/heimdalld/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Section: develop
Priority: Testing
Maintainer: Polygon <[email protected]>
Build-Depends: debhelper-compat (= 13)
Standards-Version: v1.0.2
Standards-Version: v1.0.3
Homepage: https://polygon.technology
Rules-Requires-Root: no
Package: heimdalld
Version: 1.0.2
Version: 1.0.3
Architecture: amd64
Multi-Arch: foreign
Depends:
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld
Version: 1.0.2
Version: 1.0.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.arm64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld
Version: 1.0.2
Version: 1.0.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.profile.amd64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld-profile
Version: 1.0.2
Version: 1.0.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packaging/templates/package_scripts/control.profile.arm64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: heimdalld-profile
Version: 1.0.2
Version: 1.0.3
Section: develop
Priority: standard
Maintainer: Polygon <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions packaging/templates/package_scripts/control.validator
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Section: develop
Priority: Testing
Maintainer: Polygon <[email protected]>
Build-Depends: debhelper-compat (= 13)
Standards-Version: v1.0.2
Standards-Version: v1.0.3
Homepage: https://polygon.technology
Rules-Requires-Root: no
Package: heimdalld-profile
Version: 1.0.2
Version: 1.0.3
Architecture: amd64
Multi-Arch: foreign
Depends: rabbitmq-server
Expand Down
4 changes: 2 additions & 2 deletions packaging/templates/package_scripts/control.validator.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Section: develop
Priority: Testing
Maintainer: Polygon <[email protected]>
Build-Depends: debhelper-compat (= 13)
Standards-Version: v1.0.2
Standards-Version: v1.0.3
Homepage: https://polygon.technology
Rules-Requires-Root: no
Package: heimdalld-profile
Version: 1.0.2
Version: 1.0.3
Architecture: arm64
Multi-Arch: foreign
Depends: rabbitmq-server
Expand Down
171 changes: 171 additions & 0 deletions staking/side_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package staking_test

import (
"encoding/json"
"errors"
"math/big"
"math/rand"
"testing"
Expand All @@ -22,6 +24,7 @@ import (
hmTypes "github.com/maticnetwork/heimdall/types"
"github.com/maticnetwork/heimdall/types/simulation"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -1354,3 +1357,171 @@ func (suite *SideHandlerTestSuite) TestPostHandleMsgStakeUpdate() {
require.Equal(t, acctualPower.Int64(), updatedVal.VotingPower, "Validator VotingPower should be updated to %v", newAmount.Uint64())
})
}

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

eventLogs := []string{
`{
"type": "0x2",
"root": "0x",
"status": "0x1",
"cumulativeGasUsed": "0x155957",
"logsBloom": "0x20000000000000000000000000800008000000000000000000001000000000000200000040000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000200001000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000010000000000000000000000000000000200000000000000004000000000",
"logs": [
{
"address": "0xa59c847bd5ac0172ff4fe912c5d29e5a71a7512b",
"topics": [
"0x086044c0612a8c965d4cccd907f0d588e40ad68438bd4c1274cac60f4c3a9d1f",
"0x0000000000000000000000000000000000000000000000000000000000000013",
"0x00000000000000000000000072f93a2740e00112d5f2cef404c0aa16fae21fa4",
"0x0000000000000000000000003a5f70ac0551d5fae2b2379c6e558f6b7efa6a0d"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000039400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040c8df79b1015f5bc235c9242bee499f2a5e25ad2c33b70561c2ba67118a00a1fe024dccfb65960ab91dfcd30b521fa1aa692b21ca251ec8063b2fc0a343a1b0bc",
"blockNumber": "0x116fbce",
"transactionHash": "0x496c8a0b022c3aa582f275f1f84424c679155b120fc09e7ec8051334e653ef64",
"transactionIndex": "0x10",
"blockHash": "0x1377ba799fa1f4d3924297f951e3a8095735334d1ff8099aae9467947164213f",
"logIndex": "0x14",
"removed": false
}
],
"transactionHash": "0x496c8a0b022c3aa582f275f1f84424c679155b120fc09e7ec8051334e653ef64",
"contractAddress": "0x0000000000000000000000000000000000000000",
"gasUsed": "0x75a65",
"effectiveGasPrice": "0x20fb31dfe",
"blockHash": "0x1377ba799fa1f4d3924297f951e3a8095735334d1ff8099aae9467947164213f",
"blockNumber": "0x116fbce",
"transactionIndex": "0x10"
}`,
`{
"type": "0x2",
"root": "0x",
"status": "0x1",
"cumulativeGasUsed": "0x155957",
"logsBloom": "0x20000000000000000000000000800008000000000000000000001000000000000200000040000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000200001000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000010000000000000000000000000000000200000000000000004000000000",
"logs": [
{
"address": "0xa59c847bd5ac0172ff4fe912c5d29e5a71a7512b",
"topics": [
"0x35af9eea1f0e7b300b0a14fae90139a072470e44daa3f14b5069bebbc1265bda",
"0x0000000000000000000000000000000000000000000000000000000000000013",
"0x00000000000000000000000072f93a2740e00112d5f2cef404c0aa16fae21fa4",
"0x0000000000000000000000003a5f70ac0551d5fae2b2379c6e558f6b7efa6a0d"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000039400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040c8df79b1015f5bc235c9242bee499f2a5e25ad2c33b70561c2ba67118a00a1fe024dccfb65960ab91dfcd30b521fa1aa692b21ca251ec8063b2fc0a343a1b0bc",
"blockNumber": "0x116fbce",
"transactionHash": "0x496c8a0b022c3aa582f275f1f84424c679155b120fc09e7ec8051334e653ef64",
"transactionIndex": "0x10",
"blockHash": "0x1377ba799fa1f4d3924297f951e3a8095735334d1ff8099aae9467947164213f",
"logIndex": "0x14",
"removed": false
}
],
"transactionHash": "0x496c8a0b022c3aa582f275f1f84424c679155b120fc09e7ec8051334e653ef64",
"contractAddress": "0x0000000000000000000000000000000000000000",
"gasUsed": "0x75a65",
"effectiveGasPrice": "0x20fb31dfe",
"blockHash": "0x1377ba799fa1f4d3924297f951e3a8095735334d1ff8099aae9467947164213f",
"blockNumber": "0x116fbce",
"transactionIndex": "0x10"
}`,
}

testCases := []struct {
actualEventLog string
disguisedEventLog string
decodeEventName string
expectedErr error
}{
{
actualEventLog: eventLogs[1],
disguisedEventLog: eventLogs[0],
decodeEventName: "DecodeValidatorStakeUpdateEvent",
expectedErr: errors.New("topic event mismatch"),
},
{
actualEventLog: eventLogs[0],
disguisedEventLog: eventLogs[1],
decodeEventName: "DecodeSignerUpdateEvent",
expectedErr: errors.New("topic event mismatch"),
},
}

receipt := ethTypes.Receipt{}

for _, tc := range testCases {
err := json.Unmarshal([]byte(tc.disguisedEventLog), &receipt)
if err != nil {
t.Error(err)
return
}

err = decodeEvent(t, tc.decodeEventName, receipt)
if err == nil {
t.Error(err)
return
}

assert.EqualError(t, err, tc.expectedErr.Error())

err = json.Unmarshal([]byte(tc.actualEventLog), &receipt)
if err != nil {
t.Error(err)
return
}

err = decodeEvent(t, tc.decodeEventName, receipt)
if err != nil {
t.Error(err)
return
}

assert.NoError(t, err)
}
}

func decodeEvent(t *testing.T, eventName string, receipt ethTypes.Receipt) error {
t.Helper()

var err error
contractCaller, err := helper.NewContractCaller()

if err != nil {
t.Error("Error creating contract caller")
}

switch eventName {
case "DecodeNewHeaderBlockEvent":
_, err = contractCaller.DecodeNewHeaderBlockEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeValidatorStakeUpdateEvent":
_, err = contractCaller.DecodeValidatorStakeUpdateEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeSignerUpdateEvent":
_, err = contractCaller.DecodeSignerUpdateEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeValidatorTopupFeesEvent":
_, err = contractCaller.DecodeValidatorTopupFeesEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeValidatorJoinEvent":
_, err = contractCaller.DecodeValidatorJoinEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeValidatorExitEvent":
_, err = contractCaller.DecodeValidatorExitEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeStateSyncedEvent":
_, err = contractCaller.DecodeStateSyncedEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeSlashedEvent":
_, err = contractCaller.DecodeSlashedEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

case "DecodeUnJailedEvent":
_, err = contractCaller.DecodeUnJailedEvent(receipt.Logs[0].Address, &receipt, uint64(receipt.Logs[0].Index))

default:
return errors.New("Unrecognized event")
}

return err
}

0 comments on commit 1842793

Please sign in to comment.