github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/test/vectors/statetransition_v2.go (about)

     1  package vectors
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  	"os"
     7  	"path/filepath"
     8  	"strings"
     9  )
    10  
    11  // LoadStateTransitionTestCaseV2 loads the state-transition JSON file into a
    12  // StateTransitionTestCaseV2 instance
    13  func LoadStateTransitionTestCaseV2(path string) (StateTransitionTestCaseV2, error) {
    14  	var testCase StateTransitionTestCaseV2
    15  
    16  	jsonFile, err := os.Open(filepath.Clean(path))
    17  	if err != nil {
    18  		return testCase, err
    19  	}
    20  	defer func() { _ = jsonFile.Close() }()
    21  
    22  	bytes, err := io.ReadAll(jsonFile)
    23  	if err != nil {
    24  		return testCase, err
    25  	}
    26  
    27  	err = json.Unmarshal(bytes, &testCase)
    28  	if err != nil {
    29  		return testCase, err
    30  	}
    31  	if testCase.Description == "" {
    32  		testCase.Description = strings.Replace(filepath.Base(path), ".json", "", 1)
    33  	}
    34  
    35  	return testCase, nil
    36  }