Commit a9557563 authored by mdj33's avatar mdj33 Committed by 33cn

add ut

parent 3536624c
......@@ -9,6 +9,8 @@ import (
"testing"
"github.com/33cn/chain33/blockchain"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/executor"
"github.com/33cn/chain33/mempool"
......@@ -22,6 +24,7 @@ import (
"github.com/33cn/chain33/types"
typesmocks "github.com/33cn/chain33/types/mocks"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/assert"
)
func init() {
......@@ -202,3 +205,46 @@ func (s *suiteParaClient) getParaMainBlock(height int64, BlockTime int64) *types
},
}
}
func getPrivKey(t *testing.T) crypto.PrivKey {
pk, err := common.FromHex("6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b")
assert.Nil(t, err)
secp, err := crypto.New(types.GetSignName("", types.SECP256K1))
assert.Nil(t, err)
priKey, err := secp.PrivKeyFromBytes(pk)
assert.Nil(t, err)
return priKey
}
func TestCalcCommitMsgTxs(t *testing.T) {
priKey := getPrivKey(t)
client := commitMsgClient{
privateKey: priKey,
}
nt1 := &pt.ParacrossNodeStatus{
Height: 1,
Title: "user.p.para",
}
nt2 := &pt.ParacrossNodeStatus{
Height: 2,
Title: "user.p.para",
}
notify := []*pt.ParacrossNodeStatus{nt1}
tx, count, err := client.calcCommitMsgTxs(notify)
assert.Nil(t, err)
assert.Equal(t, int64(1), count)
assert.NotNil(t, tx)
notify = append(notify, nt2)
tx, count, err = client.calcCommitMsgTxs(notify)
assert.Nil(t, err)
assert.Equal(t, int64(2), count)
assert.NotNil(t, tx)
tx, err = client.singleCalcTx(nt2)
assert.Nil(t, err)
assert.NotNil(t, tx)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment