aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-02-25 19:35:06 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:57 +0800
commitb708ec0f082d431dfe6d56882d58043811647ac7 (patch)
tree575195174be8546146d64b79760288b5f5a8e7b4 /build
parente83bcc1097d49b46b79131e546f1270b9192cc05 (diff)
downloaddexon-b708ec0f082d431dfe6d56882d58043811647ac7.tar.gz
dexon-b708ec0f082d431dfe6d56882d58043811647ac7.tar.zst
dexon-b708ec0f082d431dfe6d56882d58043811647ac7.zip
core: vm: flatten governance
Diffstat (limited to 'build')
-rw-r--r--build/testtool/testtool.go76
1 files changed, 59 insertions, 17 deletions
diff --git a/build/testtool/testtool.go b/build/testtool/testtool.go
index 801c343b6..09e94fe16 100644
--- a/build/testtool/testtool.go
+++ b/build/testtool/testtool.go
@@ -11,6 +11,8 @@ import (
"strings"
"time"
+ dexCore "github.com/dexon-foundation/dexon-consensus/core"
+
"github.com/dexon-foundation/dexon"
"github.com/dexon-foundation/dexon/accounts/abi"
"github.com/dexon-foundation/dexon/cmd/zoo/monkey"
@@ -37,14 +39,42 @@ func main() {
}
}
-func doVerifyGovCRS(args []string) {
- if len(args) < 2 {
- log.Fatal("arg length is not enough")
+func getBlockNumber(client *ethclient.Client, round int) *big.Int {
+ if round == 0 {
+ return big.NewInt(0)
+ }
+ abiObject, err := abi.JSON(strings.NewReader(vm.GovernanceABIJSON))
+ if err != nil {
+ log.Fatalf("read abi fail: %v", err)
}
- client, err := ethclient.Dial(args[0])
+ input, err := abiObject.Pack("roundHeight", big.NewInt(int64(round)))
if err != nil {
- log.Fatalf("new ethclient fail: %v", err)
+ log.Fatalf("pack input fail: %v", err)
+ }
+
+ result, err := client.CallContract(context.Background(), ethereum.CallMsg{
+ To: &vm.GovernanceContractAddress,
+ Data: input,
+ }, nil)
+ if err != nil {
+ log.Fatalf("call contract fail: %v", err)
+ }
+
+ if bytes.Equal(make([]byte, 32), result) {
+ log.Fatalf("round %d height not found", round)
+ }
+
+ roundHeight := new(big.Int)
+ if err := abiObject.Unpack(&roundHeight, "roundHeight", result); err != nil {
+ log.Fatalf("unpack output fail: %v", err)
+ }
+ return roundHeight
+}
+
+func doVerifyGovCRS(args []string) {
+ if len(args) < 2 {
+ log.Fatal("arg length is not enough")
}
abiObject, err := abi.JSON(strings.NewReader(vm.GovernanceABIJSON))
@@ -57,7 +87,14 @@ func doVerifyGovCRS(args []string) {
log.Fatalf("pasre round from arg 2 fail: %v", err)
}
- input, err := abiObject.Pack("crs", big.NewInt(int64(round)))
+ client, err := ethclient.Dial(args[0])
+ if err != nil {
+ log.Fatalf("new ethclient fail: %v", err)
+ }
+
+ blockNumber := getBlockNumber(client, round)
+
+ input, err := abiObject.Pack("crs")
if err != nil {
log.Fatalf("pack input fail: %v", err)
}
@@ -65,7 +102,7 @@ func doVerifyGovCRS(args []string) {
result, err := client.CallContract(context.Background(), ethereum.CallMsg{
To: &vm.GovernanceContractAddress,
Data: input,
- }, nil)
+ }, blockNumber)
if err != nil {
log.Fatalf("call contract fail: %v", err)
}
@@ -81,12 +118,6 @@ func doVerifyGovMPK(args []string) {
if len(args) < 3 {
log.Fatal("arg length is not enough")
}
-
- client, err := ethclient.Dial(args[0])
- if err != nil {
- log.Fatalf("new ethclient fail: %v", err)
- }
-
abiObject, err := abi.JSON(strings.NewReader(vm.GovernanceABIJSON))
if err != nil {
log.Fatalf("read abi fail: %v", err)
@@ -97,12 +128,23 @@ func doVerifyGovMPK(args []string) {
log.Fatalf("pasre round from arg 2 fail: %v", err)
}
+ if uint64(round) < dexCore.DKGDelayRound {
+ return
+ }
+
+ client, err := ethclient.Dial(args[0])
+ if err != nil {
+ log.Fatalf("new ethclient fail: %v", err)
+ }
+
+ blockNumber := getBlockNumber(client, round)
+
index, err := strconv.Atoi(args[2])
if err != nil {
- log.Fatalf("pasre round from arg 2 fail: %v", err)
+ log.Fatalf("pasre index from arg 2 fail: %v", err)
}
- input, err := abiObject.Pack("dkgMasterPublicKeys", big.NewInt(int64(round)), big.NewInt(int64(index)))
+ input, err := abiObject.Pack("dkgMasterPublicKeys", big.NewInt(int64(index)))
if err != nil {
log.Fatalf("pack input fail: %v", err)
}
@@ -110,13 +152,13 @@ func doVerifyGovMPK(args []string) {
result, err := client.CallContract(context.Background(), ethereum.CallMsg{
To: &vm.GovernanceContractAddress,
Data: input,
- }, nil)
+ }, blockNumber)
if err != nil {
log.Fatalf("call contract fail: %v", err)
}
if bytes.Equal(make([]byte, 0), result) {
- log.Fatalf("round %s index %s crs not found", args[1], args[2])
+ log.Fatalf("round %s index %s mpk not found", args[1], args[2])
}
log.Printf("get round %s index %s master public key %x", args[1], args[2], result)