Skip to content

Commit

Permalink
Add a test that demonstrates unmarshalling behavior for `getrawtransa…
Browse files Browse the repository at this point in the history
…ction` results.
  • Loading branch information
nuttycom committed Aug 13, 2024
1 parent 033d54e commit 5c11c83
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions frontend/service_test.go
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)
}
}

0 comments on commit 5c11c83

Please sign in to comment.