| 
									
										
										
										
											2018-12-03 16:50:59 +02:00
										 |  |  | // Copyright 2018 The go-ethereum Authors | 
					
						
							|  |  |  | // This file is part of go-ethereum. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // go-ethereum is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | // (at your option) any later version. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // go-ethereum is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
					
						
							|  |  |  | // GNU General Public License for more details. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 	"bytes" | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	"encoding/json" | 
					
						
							|  |  |  | 	"io/ioutil" | 
					
						
							|  |  |  | 	"reflect" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/davecgh/go-spew/spew" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/core" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 16:50:59 +02:00
										 |  |  | // Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet. | 
					
						
							|  |  |  | func TestAlethSturebyConverter(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	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] { | 
					
						
							| 
									
										
										
										
											2019-07-17 19:20:24 +08:00
										 |  |  | 				t.Logf("got: %v\nexp: %v\n", exp[i], got[i]) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 16:50:59 +02:00
										 |  |  | // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet. | 
					
						
							|  |  |  | func TestParitySturebyConverter(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	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) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 	spec, err := newParityChainSpec("stureby", &genesis, []string{}) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("failed creating chainspec: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 	enc, err := json.MarshalIndent(spec, "", "  ") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("failed encoding chainspec: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("could not read file: %v", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 	if !bytes.Equal(expBlob, enc) { | 
					
						
							|  |  |  | 		t.Fatalf("chainspec mismatch") | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |