diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-11-07 16:11:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-07 16:11:17 +0800 |
commit | 766e6aac32b8f97934833c06814c37dbdd9b7ae2 (patch) | |
tree | aac3c79c6db2c5c32de3519888b2e1253eb0fceb /core/test/utils.go | |
parent | bcdc444319ca9fe219f27e818ab9ec863d6757ea (diff) | |
download | dexon-consensus-766e6aac32b8f97934833c06814c37dbdd9b7ae2.tar dexon-consensus-766e6aac32b8f97934833c06814c37dbdd9b7ae2.tar.gz dexon-consensus-766e6aac32b8f97934833c06814c37dbdd9b7ae2.tar.bz2 dexon-consensus-766e6aac32b8f97934833c06814c37dbdd9b7ae2.tar.lz dexon-consensus-766e6aac32b8f97934833c06814c37dbdd9b7ae2.tar.xz dexon-consensus-766e6aac32b8f97934833c06814c37dbdd9b7ae2.tar.zst dexon-consensus-766e6aac32b8f97934833c06814c37dbdd9b7ae2.zip |
test: make StateChangeRequest broadcast-able (#305)
Make `test.StateChangeRequest` behaves like tx
on ethereum:
- Can be broadcasted and cached in a pool.
- Uniquely indexed, and be removed after
applied.
Changes:
- Make cloneDKGx functions in test.State as
utilities.
- Add hash and timestamp fields to
test.StateChangeRequest.
- Add two methods to test.State:
- PackOwnRequests would pack all pending
change requests owned by this instance as
byte slice, and move them to global pending
requests pool.
- AddRequestsFromOthers would add pending
change requests from others to global
pending requests pool.
- The method State.PackRequests now would pack
requests in global pending requests pool.
- The method State.Apply would remove
corresponding StateChangeRequest by hash.
Diffstat (limited to 'core/test/utils.go')
-rw-r--r-- | core/test/utils.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/core/test/utils.go b/core/test/utils.go index da76860..f5f4c36 100644 --- a/core/test/utils.go +++ b/core/test/utils.go @@ -27,6 +27,8 @@ import ( "github.com/dexon-foundation/dexon-consensus/core/crypto" "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg" + "github.com/dexon-foundation/dexon/rlp" ) func stableRandomHash(block *types.Block) (common.Hash, error) { @@ -116,3 +118,42 @@ func NewKeys(count int) ( } return } + +func cloneDKGComplaint( + comp *typesDKG.Complaint) (copied *typesDKG.Complaint) { + b, err := rlp.EncodeToBytes(comp) + if err != nil { + panic(err) + } + copied = &typesDKG.Complaint{} + if err = rlp.DecodeBytes(b, copied); err != nil { + panic(err) + } + return +} + +func cloneDKGMasterPublicKey(mpk *typesDKG.MasterPublicKey) ( + copied *typesDKG.MasterPublicKey) { + b, err := rlp.EncodeToBytes(mpk) + if err != nil { + panic(err) + } + copied = typesDKG.NewMasterPublicKey() + if err = rlp.DecodeBytes(b, copied); err != nil { + panic(err) + } + return +} + +func cloneDKGFinalize(final *typesDKG.Finalize) ( + copied *typesDKG.Finalize) { + b, err := rlp.EncodeToBytes(final) + if err != nil { + panic(err) + } + copied = &typesDKG.Finalize{} + if err = rlp.DecodeBytes(b, copied); err != nil { + panic(err) + } + return +} |