aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/puppeth/puppeth_test.go
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2018-11-25 06:22:25 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-12-03 18:34:41 +0800
commit8698fbabf6c7811e8eec6e84512510e9c9a4eb45 (patch)
treebfd4570f18e332e2d51a140aa331ab9507bd2983 /cmd/puppeth/puppeth_test.go
parenta3fd415c0f983cae35c329d97e0b6707561daef6 (diff)
downloadgo-tangerine-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar
go-tangerine-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.gz
go-tangerine-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.bz2
go-tangerine-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.lz
go-tangerine-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.xz
go-tangerine-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.tar.zst
go-tangerine-8698fbabf6c7811e8eec6e84512510e9c9a4eb45.zip
cmd/puppeth: implement chainspec converters
Diffstat (limited to 'cmd/puppeth/puppeth_test.go')
-rw-r--r--cmd/puppeth/puppeth_test.go91
1 files changed, 91 insertions, 0 deletions
diff --git a/cmd/puppeth/puppeth_test.go b/cmd/puppeth/puppeth_test.go
new file mode 100644
index 000000000..ae0752d54
--- /dev/null
+++ b/cmd/puppeth/puppeth_test.go
@@ -0,0 +1,91 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/davecgh/go-spew/spew"
+ "github.com/ethereum/go-ethereum/core"
+)
+
+func TestConverter_AlethStureby(t *testing.T) {
+ blob, err := ioutil.ReadFile("testdata/stureby_geth.json")
+ if err != nil {
+ t.Fatalf("could not read file: %v", err)
+ }
+ var genesis core.Genesis
+ if err := json.Unmarshal(blob, &genesis); err != nil {
+ t.Fatalf("failed parsing genesis: %v", err)
+ }
+ spec, err := newAlethGenesisSpec("stureby", &genesis)
+ if err != nil {
+ t.Fatalf("failed creating chainspec: %v", err)
+ }
+
+ expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json")
+ if err != nil {
+ t.Fatalf("could not read file: %v", err)
+ }
+ expspec := &alethGenesisSpec{}
+ if err := json.Unmarshal(expBlob, expspec); err != nil {
+ t.Fatalf("failed parsing genesis: %v", err)
+ }
+ if !reflect.DeepEqual(expspec, spec) {
+ t.Errorf("chainspec mismatch")
+ c := spew.ConfigState{
+ DisablePointerAddresses: true,
+ SortKeys: true,
+ }
+ exp := strings.Split(c.Sdump(expspec), "\n")
+ got := strings.Split(c.Sdump(spec), "\n")
+ for i := 0; i < len(exp) && i < len(got); i++ {
+ if exp[i] != got[i] {
+ fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
+ }
+ }
+ }
+}
+
+func TestConverter_ParityStureby(t *testing.T) {
+ blob, err := ioutil.ReadFile("testdata/stureby_geth.json")
+ if err != nil {
+ t.Fatalf("could not read file: %v", err)
+ }
+ var genesis core.Genesis
+ if err := json.Unmarshal(blob, &genesis); err != nil {
+ t.Fatalf("failed parsing genesis: %v", err)
+ }
+ spec, err := newParityChainSpec("Stureby", &genesis, []string{})
+ if err != nil {
+ t.Fatalf("failed creating chainspec: %v", err)
+ }
+
+ expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json")
+ if err != nil {
+ t.Fatalf("could not read file: %v", err)
+ }
+ expspec := &parityChainSpec{}
+ if err := json.Unmarshal(expBlob, expspec); err != nil {
+ t.Fatalf("failed parsing genesis: %v", err)
+ }
+ expspec.Nodes = []string{}
+
+ if !reflect.DeepEqual(expspec, spec) {
+ t.Errorf("chainspec mismatch")
+ c := spew.ConfigState{
+ DisablePointerAddresses: true,
+ SortKeys: true,
+ }
+ exp := strings.Split(c.Sdump(expspec), "\n")
+ got := strings.Split(c.Sdump(spec), "\n")
+ for i := 0; i < len(exp) && i < len(got); i++ {
+ if exp[i] != got[i] {
+ fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
+ }
+ }
+ }
+}