示例#1
0
func TestDupeoutTxSignable(t *testing.T) {
	privAcc := acm.GenPrivAccount()
	partSetHeader := PartSetHeader{Total: 10, Hash: []byte("partsethash")}
	voteA := &Vote{
		Height:           10,
		Round:            2,
		Type:             VoteTypePrevote,
		BlockHash:        []byte("myblockhash"),
		BlockPartsHeader: partSetHeader,
	}
	sig := privAcc.Sign(chainID, voteA)
	voteA.Signature = sig.(acm.SignatureEd25519)
	voteB := voteA.Copy()
	voteB.BlockHash = []byte("myotherblockhash")
	sig = privAcc.Sign(chainID, voteB)
	voteB.Signature = sig.(acm.SignatureEd25519)

	dupeoutTx := &DupeoutTx{
		Address: []byte("address1"),
		VoteA:   *voteA,
		VoteB:   *voteB,
	}
	signBytes := acm.SignBytes(chainID, dupeoutTx)
	signStr := string(signBytes)
	expected := Fmt(`{"chain_id":"%s","tx":[20,{"address":"6164647265737331","vote_a":%v,"vote_b":%v}]}`,
		config.GetString("chain_id"), *voteA, *voteB)
	if signStr != expected {
		t.Errorf("Got unexpected sign string for DupeoutTx")
	}
}
示例#2
0
func RandAccount(randBalance bool, minBalance int64) (*account.Account, *account.PrivAccount) {
	privAccount := account.GenPrivAccount()
	perms := ptypes.DefaultAccountPermissions
	acc := &account.Account{
		Address:     privAccount.PubKey.Address(),
		PubKey:      privAccount.PubKey,
		Sequence:    RandInt(),
		Balance:     minBalance,
		Permissions: perms,
	}
	if randBalance {
		acc.Balance += int64(RandUint32())
	}
	return acc, privAccount
}
示例#3
0
func BenchmarkValidatorSetCopy(b *testing.B) {
	b.StopTimer()
	vset := NewValidatorSet([]*Validator{})
	for i := 0; i < 1000; i++ {
		privAccount := account.GenPrivAccount()
		val := &Validator{
			Address: privAccount.Address,
			PubKey:  privAccount.PubKey.(account.PubKeyEd25519),
		}
		if !vset.Add(val) {
			panic("Failed to add validator")
		}
	}
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		vset.Copy()
	}
}
示例#4
0
func GenPrivAccount() (*acm.PrivAccount, error) {
	return acm.GenPrivAccount(), nil
}
示例#5
0
// Generate a new Private Key Account.
func (this *accounts) GenPrivAccount() (*account.PrivAccount, error) {
	pa := account.GenPrivAccount()
	return pa, nil
}
示例#6
0
func GenPrivAccount() (*ctypes.ResultGenPrivAccount, error) {
	return &ctypes.ResultGenPrivAccount{acm.GenPrivAccount()}, nil
}