-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test that demonstrates unmarshalling behavior for `getrawtransa…
…ction` results.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 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,38 @@ | ||
package frontend | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/zcash/lightwalletd/common" | ||
) | ||
|
||
func TestZcashdRpcReplyUnmarshalling(t *testing.T) { | ||
var txinfo0 common.ZcashdRpcReplyGetrawtransaction | ||
err0 := json.Unmarshal([]byte("{\"hex\": \"deadbeef\", \"height\": 123456}"), &txinfo0) | ||
if err0 != nil { | ||
t.Fatal("Failed to unmarshal tx with known height.") | ||
} | ||
if txinfo0.Height != 123456 { | ||
t.Errorf("Unmarshalled incorrect height: got: %d, want: 123456.", txinfo0.Height) | ||
} | ||
|
||
var txinfo1 common.ZcashdRpcReplyGetrawtransaction | ||
err1 := json.Unmarshal([]byte("{\"hex\": \"deadbeef\", \"height\": -1}"), &txinfo1) | ||
if err1 != nil { | ||
t.Fatal("failed to unmarshal tx not in main chain") | ||
} | ||
if txinfo1.Height != -1 { | ||
t.Errorf("Unmarshalled incorrect height: got: %d, want: -1.", txinfo1.Height) | ||
} | ||
|
||
var txinfo2 common.ZcashdRpcReplyGetrawtransaction | ||
err2 := json.Unmarshal([]byte("{\"hex\": \"deadbeef\"}"), &txinfo2) | ||
if err2 != nil { | ||
t.Fatal("failed to unmarshal reply lacking height data") | ||
} | ||
if txinfo2.Height != 0 { | ||
t.Errorf("Unmarshalled incorrect height: got: %d, want: 0.", txinfo2.Height) | ||
} | ||
} | ||
|