github.com/theQRL/go-zond@v0.2.1/cmd/gzond/exportcmd_test.go (about)

     1  // Copyright 2022 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"bytes"
    21  	"fmt"
    22  	"os"
    23  	"testing"
    24  
    25  	"github.com/theQRL/go-zond/common"
    26  )
    27  
    28  func initGzond(t *testing.T) string {
    29  	args := []string{"--networkid=42", "init", "./testdata/genesis.json"}
    30  	t.Logf("Initializing gzond: %v ", args)
    31  	g := runGzond(t, args...)
    32  	datadir := g.Datadir
    33  	g.WaitExit()
    34  	return datadir
    35  }
    36  
    37  // TestExport does a basic test of "gzond export", exporting the test-genesis.
    38  func TestExport(t *testing.T) {
    39  	outfile := fmt.Sprintf("%v/testExport.out", os.TempDir())
    40  	defer os.Remove(outfile)
    41  	gzond := runGzond(t, "--datadir", initGzond(t), "export", outfile)
    42  	gzond.WaitExit()
    43  	if have, want := gzond.ExitStatus(), 0; have != want {
    44  		t.Errorf("exit error, have %d want %d", have, want)
    45  	}
    46  	have, err := os.ReadFile(outfile)
    47  	if err != nil {
    48  		t.Fatal(err)
    49  	}
    50  	want := common.FromHex("0xf90266f90261a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a08758259b018f7bce3d2be2ddb62f325eaeea0a0c188cf96623eab468a4413e03a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080837a12008080b875000000000000000000000000000000000000000000000000000000000000000002f0d131f1f97aef08aec6e3291b957d9efe71050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000843b9aca00a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421c0c0")
    51  	if !bytes.Equal(have, want) {
    52  		t.Fatalf("wrong content exported")
    53  	}
    54  }