Skip to content

Commit

Permalink
Added unit test cases in side handler of staking
Browse files Browse the repository at this point in the history
  • Loading branch information
VAIBHAVJINDAL3012 committed Nov 2, 2023
1 parent 4ebd4bb commit 731c2c7
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 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 @@ -26,6 +28,8 @@ import (
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/secp256k1"

cmn "github.com/ethereum/go-ethereum/common"
)

//
Expand Down Expand Up @@ -1354,3 +1358,103 @@ 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()
contractCaller, err := helper.NewContractCaller()
if err != nil {
t.Error("Error creating contract caller")
}

receipt := ethTypes.Receipt{}

err = json.Unmarshal([]byte(`{
"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"
}
`), &receipt)

if err != nil {
t.Error(err)
return
}

_, err = contractCaller.DecodeValidatorStakeUpdateEvent(cmn.HexToAddress("0xa59c847bd5ac0172ff4fe912c5d29e5a71a7512b"), &receipt, 0x14)
if err.Error() != errors.New("topic event mismatch").Error() {
t.Error(err)
return
}

err = json.Unmarshal([]byte(`{
"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"
}
`), &receipt)

if err != nil {
t.Error(err)
return
}

_, err = contractCaller.DecodeValidatorStakeUpdateEvent(cmn.HexToAddress("0xa59c847bd5ac0172ff4fe912c5d29e5a71a7512b"), &receipt, 0x14)
if err != nil {
t.Error(err)
return
}
}

0 comments on commit 731c2c7

Please sign in to comment.