aboutsummaryrefslogtreecommitdiffstats
path: root/core/test/state-change-request.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-06 14:30:05 +0800
committerGitHub <noreply@github.com>2018-12-06 14:30:05 +0800
commit41753e517c68575589c485b3f9570db94e59bcd0 (patch)
tree88ca8e57415164bce765658f3f55d51e85646eb3 /core/test/state-change-request.go
parent4eb02f1dd96e136b0f7cf7eff792da1e44176713 (diff)
downloaddexon-consensus-41753e517c68575589c485b3f9570db94e59bcd0.tar
dexon-consensus-41753e517c68575589c485b3f9570db94e59bcd0.tar.gz
dexon-consensus-41753e517c68575589c485b3f9570db94e59bcd0.tar.bz2
dexon-consensus-41753e517c68575589c485b3f9570db94e59bcd0.tar.lz
dexon-consensus-41753e517c68575589c485b3f9570db94e59bcd0.tar.xz
dexon-consensus-41753e517c68575589c485b3f9570db94e59bcd0.tar.zst
dexon-consensus-41753e517c68575589c485b3f9570db94e59bcd0.zip
test: allow to log in test.State (#359)
Diffstat (limited to 'core/test/state-change-request.go')
-rw-r--r--core/test/state-change-request.go58
1 files changed, 57 insertions, 1 deletions
diff --git a/core/test/state-change-request.go b/core/test/state-change-request.go
index 0f49db0..84d4d3f 100644
--- a/core/test/state-change-request.go
+++ b/core/test/state-change-request.go
@@ -18,10 +18,13 @@
package test
import (
+ "fmt"
+ "math"
"time"
"github.com/dexon-foundation/dexon-consensus/common"
"github.com/dexon-foundation/dexon-consensus/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus/core/types"
typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg"
"github.com/dexon-foundation/dexon/rlp"
)
@@ -43,7 +46,6 @@ const (
StateChangeLambdaDKG
StateChangeRoundInterval
StateChangeMinBlockInterval
- StateChangeMaxBlockInterval
StateChangeK
StateChangePhiRatio
StateChangeNotarySetSize
@@ -133,3 +135,57 @@ func (req *StateChangeRequest) Equal(other *StateChangeRequest) error {
}
return ErrStatePendingChangesNotEqual
}
+
+// String dump the state change request into string form.
+func (req *StateChangeRequest) String() (ret string) {
+ ret = "stateChangeRequest"
+ switch req.Type {
+ case StateChangeNothing:
+ ret += "{Type:Nothing}"
+ case StateAddCRS:
+ crsReq := req.Payload.(*crsAdditionRequest)
+ ret += fmt.Sprintf("{Type:AddCRS Round:%v CRS:%s",
+ crsReq.Round,
+ crsReq.CRS.String()[:6])
+ case StateAddDKGComplaint:
+ ret += fmt.Sprintf(
+ "{Type:AddDKGComplaint %s", req.Payload.(*typesDKG.Complaint))
+ case StateAddDKGMasterPublicKey:
+ ret += fmt.Sprintf(
+ "{Type:AddDKGMasterPublicKey %s",
+ req.Payload.(*typesDKG.MasterPublicKey))
+ case StateAddDKGFinal:
+ ret += fmt.Sprintf(
+ "{Type:AddDKGFinal %s", req.Payload.(*typesDKG.Finalize))
+ case StateChangeNumChains:
+ ret += fmt.Sprintf("{Type:ChangeNumChains %v", req.Payload.(uint32))
+ case StateChangeLambdaBA:
+ ret += fmt.Sprintf(
+ "{Type:ChangeLambdaBA %v", time.Duration(req.Payload.(uint64)))
+ case StateChangeLambdaDKG:
+ ret += fmt.Sprintf(
+ "{Type:ChangeLambdaDKG %v", time.Duration(req.Payload.(uint64)))
+ case StateChangeRoundInterval:
+ ret += fmt.Sprintf(
+ "{Type:ChangeRoundInterval %v", time.Duration(req.Payload.(uint64)))
+ case StateChangeMinBlockInterval:
+ ret += fmt.Sprintf(
+ "{Type:ChangeMinBlockInterval %v",
+ time.Duration(req.Payload.(uint64)))
+ case StateChangeK:
+ ret += fmt.Sprintf("Type:ChangeK %v", req.Payload.(uint64))
+ case StateChangePhiRatio:
+ ret += fmt.Sprintf(
+ "{Type:ChangePhiRatio %v", math.Float32frombits(req.Payload.(uint32)))
+ case StateChangeNotarySetSize:
+ ret += fmt.Sprintf("{Type:ChangeNotarySetSize %v", req.Payload.(uint32))
+ case StateChangeDKGSetSize:
+ ret += fmt.Sprintf("{Type:ChangeDKGSetSize %v", req.Payload.(uint32))
+ case StateAddNode:
+ ret += fmt.Sprintf(
+ "{Type:AddNode %s",
+ types.NewNodeID(req.Payload.(crypto.PublicKey)).String()[:6])
+ }
+ panic(fmt.Errorf(
+ "attempting to dump unknown type of state change request: %v", req.Type))
+}