-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account-based chain phase 2: add ULT test for Vote
- Loading branch information
Showing
4 changed files
with
104 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2018 IoTeX | ||
// This is an alpha (internal) release and is not suitable for production. This source code is provided ‘as is’ and no | ||
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent | ||
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache | ||
// License 2.0 that can be found in the LICENSE file. | ||
|
||
package action | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/iotexproject/iotex-core/iotxaddress" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVote(t *testing.T) { | ||
assert := assert.New(t) | ||
sender, err := iotxaddress.NewAddress(true, chainid) | ||
assert.Nil(err) | ||
recipient, err := iotxaddress.NewAddress(true, chainid) | ||
assert.Nil(err) | ||
// Create new vote and put on wire | ||
vote := NewVote(0, sender.PublicKey, recipient.PublicKey) | ||
raw, err := vote.Serialize() | ||
assert.Nil(err) | ||
// Sign the transfer | ||
signed, err := SignVote(raw, sender) | ||
assert.Nil(err) | ||
// deserialize | ||
vote2 := &Vote{} | ||
assert.Nil(vote2.Deserialize(signed)) | ||
// test data match before/after serialization | ||
assert.Equal(vote.Hash(), vote2.Hash()) | ||
// test signature | ||
assert.Nil(vote2.Verify(sender)) | ||
assert.NotNil(vote2.Verify(recipient)) | ||
assert.NotNil(vote.Verify(sender)) | ||
} |