Skip to content

Commit

Permalink
fix: fix all failed tests
Browse files Browse the repository at this point in the history
Signed-off-by: 170210 <j170210@icloud.com>
  • Loading branch information
170210 committed Mar 11, 2024
1 parent 8ac1f7d commit fb908dc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
13 changes: 9 additions & 4 deletions blockchain/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package blockchain
import (
"encoding/hex"
"fmt"
"github.com/gogo/protobuf/proto"
"math"
"testing"

"github.com/Finschia/ostracon/crypto"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"math"
"testing"

voivrf "github.com/oasisprotocol/curve25519-voi/primitives/ed25519/extra/ecvrf"
bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"

ocbcproto "github.com/Finschia/ostracon/proto/ostracon/blockchain"
Expand Down Expand Up @@ -146,6 +148,9 @@ func TestEncodeDecodeValidateMsg(t *testing.T) {
nil,
sm.InitStateVersion.Consensus)
block.ProposerAddress = make([]byte, crypto.AddressSize)
round := int32(0)
proof := make([]byte, voivrf.ProofSize)
block.Entropy.Populate(round, proof)
bpb, err := block.ToProto()
require.NoError(t, err)

Expand All @@ -167,7 +172,7 @@ func TestEncodeDecodeValidateMsg(t *testing.T) {
{
name: "ocbcproto.BlockResponse", // Ostracon
args: args{pb: &ocbcproto.BlockResponse{Block: bpb}},
want: []byte{0x1a, 0xf0, 0x1, 0xa, 0xed, 0x1, 0xa, 0x93, 0x1, 0xa, 0x2, 0x8, 0xb, 0x18, 0x3, 0x22, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x2a, 0x2, 0x12, 0x0, 0x32, 0x20, 0x1e, 0xba, 0x40, 0x13, 0xa, 0xf2, 0x5e, 0xd1, 0x9, 0x5f, 0x67, 0x86, 0xe5, 0x8d,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0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x22, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc2, 0x3e, 0x52, 0x12, 0x50, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
wantErr: assert.NoError,
},
{
Expand Down
7 changes: 6 additions & 1 deletion rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

cfg "github.com/Finschia/ostracon/config"
"github.com/Finschia/ostracon/crypto"
"github.com/Finschia/ostracon/crypto/ed25519"
tmrand "github.com/Finschia/ostracon/libs/rand"
ctypes "github.com/Finschia/ostracon/rpc/core/types"
rpctypes "github.com/Finschia/ostracon/rpc/jsonrpc/types"
Expand Down Expand Up @@ -306,7 +307,11 @@ func storeTestBlocks(startHeight, numToMakeBlocks, numToMakeTxs int64, state sm.
env.TxIndexer.Index(&abci.TxResult{Height: height, Index: uint32(txIndex), Tx: tx}) // nolint:errcheck
}
lastCommit := types.NewCommit(lastHeight, round, blockID, commitSigs)
block, _ := state.MakeBlock(height, txs, lastCommit, nil, proposer.Address, round, nil)
message := state.MakeHashMessage(round)
pk := ed25519.GenPrivKeyFromSecret([]byte("test private validator"))
privVal := types.NewMockPVWithParams(pk, false, false)
proof, _ := privVal.GenerateVRFProof(message)
block, _ := state.MakeBlock(height, txs, lastCommit, nil, proposer.Address, round, proof)
blockPart := block.MakePartSet(partSize)
// Indexing
env.BlockIndexer.Index(types.EventDataNewBlockHeader{Header: block.Header}) // nolint:errcheck
Expand Down
8 changes: 7 additions & 1 deletion store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

cfg "github.com/Finschia/ostracon/config"
"github.com/Finschia/ostracon/crypto"
"github.com/Finschia/ostracon/crypto/ed25519"
"github.com/Finschia/ostracon/libs/log"
tmrand "github.com/Finschia/ostracon/libs/rand"
sm "github.com/Finschia/ostracon/state"
Expand Down Expand Up @@ -51,8 +52,13 @@ func makeTxs(height int64) (txs []types.Tx) {
}

func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block {
round := int32(0)
message := state.MakeHashMessage(round)
pk := ed25519.GenPrivKeyFromSecret([]byte("test private validator"))
privVal := types.NewMockPVWithParams(pk, false, false)
proof, _ := privVal.GenerateVRFProof(message)
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil,
state.Validators.SelectProposer(state.LastProofHash, height, 0).Address, 0, nil)
state.Validators.SelectProposer(state.LastProofHash, height, round).Address, round, proof)
return block
}

Expand Down
5 changes: 4 additions & 1 deletion types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ func TestBlockValidateBasic(t *testing.T) {
i := i
t.Run(tc.testName, func(t *testing.T) {
block := MakeBlock(h, txs, commit, evList, TestConsensusVersion)
block.ProposerAddress = valSet.SelectProposer([]byte{}, block.Height, 0).Address
round := int32(0)
block.ProposerAddress = valSet.SelectProposer([]byte{}, block.Height, round).Address
proof := make([]byte, vrf.ProofSize)
block.Entropy.Populate(round, proof)
tc.malleateBlock(block)
err = block.ValidateBasic()
assert.Equal(t, tc.expErr, err != nil, "#%d: %v", i, err)
Expand Down

0 comments on commit fb908dc

Please sign in to comment.