forked from cosmos/ibc-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring go test cases to be in json format
To make test cases more reusable by the different implementation present in this repo, this commit moves test cases in the go reference implementation to json format in testdata.
- Loading branch information
Giulio
committed
Nov 12, 2021
1 parent
dc210c0
commit 552c01c
Showing
14 changed files
with
1,140 additions
and
830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ics23 | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
type LeafOpTestStruct struct { | ||
Op *LeafOp | ||
Key []byte | ||
Value []byte | ||
IsErr bool | ||
Expected []byte | ||
} | ||
|
||
func LeafOpTestData(t *testing.T) map[string]LeafOpTestStruct { | ||
fname := filepath.Join("..", "testdata", "TestLeafOpData.json") | ||
ffile, err := os.Open(fname) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var cases map[string]LeafOpTestStruct | ||
jsonDecoder := json.NewDecoder(ffile) | ||
err = jsonDecoder.Decode(&cases) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return cases | ||
} | ||
|
||
type InnerOpTestStruct struct { | ||
Op *InnerOp | ||
Child []byte | ||
IsErr bool | ||
Expected []byte | ||
} | ||
|
||
func InnerOpTestData(t *testing.T) map[string]InnerOpTestStruct { | ||
fname := filepath.Join("..", "testdata", "TestInnerOpData.json") | ||
ffile, err := os.Open(fname) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var cases map[string]InnerOpTestStruct | ||
jsonDecoder := json.NewDecoder(ffile) | ||
err = jsonDecoder.Decode(&cases) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return cases | ||
} | ||
|
||
type DoHashTestStruct struct { | ||
HashOp HashOp | ||
Preimage string | ||
ExpectedHash string | ||
} | ||
|
||
func DoHashTestData(t *testing.T) map[string]DoHashTestStruct { | ||
fname := filepath.Join("..", "testdata", "TestDoHashData.json") | ||
ffile, err := os.Open(fname) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var cases map[string]DoHashTestStruct | ||
jsonDecoder := json.NewDecoder(ffile) | ||
err = jsonDecoder.Decode(&cases) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return cases | ||
} | ||
|
||
func toHex(data []byte) string { | ||
return hex.EncodeToString(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.