From c7f80952c4373dac85590036676ca0e7c4cc02f5 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Wed, 4 Sep 2019 18:08:16 -0700 Subject: [PATCH] move test to shardingconfig --- .../configs/sharding/shardingconfig_test.go | 24 +++++++++++++++ internal/hmyapi/blockchain_test.go | 29 ------------------- 2 files changed, 24 insertions(+), 29 deletions(-) delete mode 100644 internal/hmyapi/blockchain_test.go diff --git a/internal/configs/sharding/shardingconfig_test.go b/internal/configs/sharding/shardingconfig_test.go index 29f322e6d..ef02c5c20 100644 --- a/internal/configs/sharding/shardingconfig_test.go +++ b/internal/configs/sharding/shardingconfig_test.go @@ -1,6 +1,7 @@ package shardingconfig import ( + "fmt" "math/big" "testing" ) @@ -86,3 +87,26 @@ func TestCalcEpochNumber(t *testing.T) { } } } + +func TestGetShardingStructure(t *testing.T) { + shardID := 0 + numShard := 4 + res := genShardingStructure(numShard, shardID, "http://s%d.t.hmy.io:9500", "ws://s%d.t.hmy.io:9800") + if len(res) != 4 || !res[0]["current"].(bool) || res[1]["current"].(bool) || res[2]["current"].(bool) || res[3]["current"].(bool) { + t.Error("Error when generating sharding structure") + } + for i := 0; i < numShard; i++ { + if res[i]["current"].(bool) != (i == shardID) { + t.Error("Error when generating sharding structure") + } + if res[i]["shardID"].(int) != i { + t.Error("Error when generating sharding structure") + } + if res[i]["http"].(string) != fmt.Sprintf("http://s%d.t.hmy.io:9500", i) { + t.Error("Error when generating sharding structure") + } + if res[i]["ws"].(string) != fmt.Sprintf("ws://s%d.t.hmy.io:9800", i) { + t.Error("Error when generating sharding structure") + } + } +} diff --git a/internal/hmyapi/blockchain_test.go b/internal/hmyapi/blockchain_test.go deleted file mode 100644 index 330ad502c..000000000 --- a/internal/hmyapi/blockchain_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package hmyapi - -import ( - "fmt" - "testing" -) - -func TestGetShardingStructure(t *testing.T) { - shardID := 0 - numShard := 4 - res := GenShardingStructure(uint32(numShard), uint32(shardID), "http://s%d.t.hmy.io:9500", "ws://s%d.t.hmy.io:9800") - if len(res) != 4 || !res[0]["current"].(bool) || res[1]["current"].(bool) || res[2]["current"].(bool) || res[3]["current"].(bool) { - t.Error("Error when generating sharding structure") - } - for i := 0; i < numShard; i++ { - if res[i]["current"].(bool) != (i == shardID) { - t.Error("Error when generating sharding structure") - } - if res[i]["shardID"].(int) != i { - t.Error("Error when generating sharding structure") - } - if res[i]["http"].(string) != fmt.Sprintf("http://s%d.t.hmy.io:9500", i) { - t.Error("Error when generating sharding structure") - } - if res[i]["ws"].(string) != fmt.Sprintf("ws://s%d.t.hmy.io:9800", i) { - t.Error("Error when generating sharding structure") - } - } -}