From 766e6aac32b8f97934833c06814c37dbdd9b7ae2 Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Wed, 7 Nov 2018 16:11:17 +0800 Subject: 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. --- core/test/utils.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'core/test/utils.go') 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 +} -- cgit v1.2.3