Skip to content

Commit

Permalink
test(rpc): test non-nil consensus params
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Sep 19, 2024
1 parent 79c4540 commit 59b42e3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
40 changes: 26 additions & 14 deletions internal/rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
sm "github.com/dashpay/tenderdash/internal/state"
"github.com/dashpay/tenderdash/internal/state/mocks"
"github.com/dashpay/tenderdash/proto/tendermint/state"
"github.com/dashpay/tenderdash/proto/tendermint/types"
"github.com/dashpay/tenderdash/rpc/coretypes"
tmtypes "github.com/dashpay/tenderdash/types"
)

func TestBlockchainInfo(t *testing.T) {
Expand Down Expand Up @@ -77,6 +79,11 @@ func TestBlockResults(t *testing.T) {
{Code: 0, Data: []byte{0x02}, Log: "ok", GasUsed: 5},
{Code: 1, Log: "not ok", GasUsed: 0},
},
ConsensusParamUpdates: &types.ConsensusParams{
Version: &types.VersionParams{
AppVersion: 1,
},
},
},
}

Expand All @@ -98,25 +105,30 @@ func TestBlockResults(t *testing.T) {
{0, true, nil},
{101, true, nil},
{100, false, &coretypes.ResultBlockResults{
Height: 100,
TxsResults: results.ProcessProposal.TxResults,
TotalGasUsed: 15,
FinalizeBlockEvents: results.ProcessProposal.Events,
ValidatorSetUpdate: results.ProcessProposal.ValidatorSetUpdate,
ConsensusParamUpdates: consensusParamsPtrFromProtoPtr(results.ProcessProposal.ConsensusParamUpdates),
Height: 100,
TxsResults: results.ProcessProposal.TxResults,
TotalGasUsed: 15,
FinalizeBlockEvents: results.ProcessProposal.Events,
ValidatorSetUpdate: results.ProcessProposal.ValidatorSetUpdate,
ConsensusParamUpdates: &tmtypes.ConsensusParams{
Version: tmtypes.VersionParams{AppVersion: 1},
},
}},
}

ctx := context.Background()
for _, tc := range testCases {
res, err := env.BlockResults(ctx, &coretypes.RequestBlockInfo{
Height: (*coretypes.Int64)(&tc.height),
t.Run("", func(t *testing.T) {
res, err := env.BlockResults(ctx, &coretypes.RequestBlockInfo{
Height: (*coretypes.Int64)(&tc.height),
})
if tc.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
t.Logf("Consensus params: %+v", res.ConsensusParamUpdates)
assert.Equal(t, tc.wantRes, res)
}
})
if tc.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tc.wantRes, res)
}
}
}
11 changes: 11 additions & 0 deletions types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@ func TestProto(t *testing.T) {
}
}

func TestFromProto(t *testing.T) {
params := []tmproto.ConsensusParams{
{},
}

for i := range params {
pbParams := params[i]
assert.NotPanics(t, func() { ConsensusParamsFromProto(pbParams) })
}
}

func durationPtr(t time.Duration) *time.Duration {
return &t
}

0 comments on commit 59b42e3

Please sign in to comment.