parser: break header checks into subroutine
This commit is contained in:
@@ -28,13 +28,15 @@ type joinSplitTestVector struct {
|
|||||||
encCiphertexts []string // 1202 [N_new][601]byte
|
encCiphertexts []string // 1202 [N_new][601]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/zcash/zips/blob/master/zip-0143.rst
|
type zip143test struct {
|
||||||
var zip143tests = []struct {
|
|
||||||
header, nVersionGroupId, nLockTime, nExpiryHeight string
|
header, nVersionGroupId, nLockTime, nExpiryHeight string
|
||||||
vin, vout [][]string
|
vin, vout [][]string
|
||||||
vJoinSplits []joinSplitTestVector
|
vJoinSplits []joinSplitTestVector
|
||||||
joinSplitPubKey, joinSplitSig string
|
joinSplitPubKey, joinSplitSig string
|
||||||
}{
|
}
|
||||||
|
|
||||||
|
// https://github.com/zcash/zips/blob/master/zip-0143.rst
|
||||||
|
var zip143tests = []zip143test{
|
||||||
{
|
{
|
||||||
// Test vector 1
|
// Test vector 1
|
||||||
header: "03000080",
|
header: "03000080",
|
||||||
@@ -165,38 +167,8 @@ func TestSproutTransactionParser(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
le := binary.LittleEndian
|
|
||||||
|
|
||||||
// Transaction metadata
|
// Transaction metadata
|
||||||
|
if ok := subTestCommonBlockMeta(&tt, tx, t, i); !ok {
|
||||||
headerBytes, _ := hex.DecodeString(tt.header)
|
|
||||||
header := le.Uint32(headerBytes)
|
|
||||||
if (header >> 31) == 1 != tx.fOverwintered {
|
|
||||||
t.Errorf("Test %d: unexpected fOverwintered", i)
|
|
||||||
}
|
|
||||||
if (header & 0x7FFFFFFF) != tx.version {
|
|
||||||
t.Errorf("Test %d: unexpected tx version", i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
versionGroupBytes, _ := hex.DecodeString(tt.nVersionGroupId)
|
|
||||||
versionGroup := le.Uint32(versionGroupBytes)
|
|
||||||
if versionGroup != tx.nVersionGroupId {
|
|
||||||
t.Errorf("Test %d: unexpected versionGroupId", i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
lockTimeBytes, _ := hex.DecodeString(tt.nLockTime)
|
|
||||||
lockTime := le.Uint32(lockTimeBytes)
|
|
||||||
if lockTime != tx.nLockTime {
|
|
||||||
t.Errorf("Test %d: unexpected nLockTime", i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
expiryHeightBytes, _ := hex.DecodeString(tt.nExpiryHeight)
|
|
||||||
expiryHeight := le.Uint32(expiryHeightBytes)
|
|
||||||
if expiryHeight != tx.nExpiryHeight {
|
|
||||||
t.Errorf("Test %d: unexpected nExpiryHeight", i)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +200,42 @@ func TestSproutTransactionParser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func subTestCommonBlockMeta(tt *zip143test, tx *transaction, t *testing.T, caseNum int) bool {
|
||||||
|
headerBytes, _ := hex.DecodeString(tt.header)
|
||||||
|
header := binary.LittleEndian.Uint32(headerBytes)
|
||||||
|
if (header >> 31) == 1 != tx.fOverwintered {
|
||||||
|
t.Errorf("Test %d: unexpected fOverwintered", caseNum)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (header & 0x7FFFFFFF) != tx.version {
|
||||||
|
t.Errorf("Test %d: unexpected tx version", caseNum)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
versionGroupBytes, _ := hex.DecodeString(tt.nVersionGroupId)
|
||||||
|
versionGroup := binary.LittleEndian.Uint32(versionGroupBytes)
|
||||||
|
if versionGroup != tx.nVersionGroupId {
|
||||||
|
t.Errorf("Test %d: unexpected versionGroupId", caseNum)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
lockTimeBytes, _ := hex.DecodeString(tt.nLockTime)
|
||||||
|
lockTime := binary.LittleEndian.Uint32(lockTimeBytes)
|
||||||
|
if lockTime != tx.nLockTime {
|
||||||
|
t.Errorf("Test %d: unexpected nLockTime", caseNum)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
expiryHeightBytes, _ := hex.DecodeString(tt.nExpiryHeight)
|
||||||
|
expiryHeight := binary.LittleEndian.Uint32(expiryHeightBytes)
|
||||||
|
if expiryHeight != tx.nExpiryHeight {
|
||||||
|
t.Errorf("Test %d: unexpected nExpiryHeight", caseNum)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func subTestJoinSplits(testJoinSplits []joinSplitTestVector, txJoinSplits []*joinSplit, t *testing.T, caseNum int) bool {
|
func subTestJoinSplits(testJoinSplits []joinSplitTestVector, txJoinSplits []*joinSplit, t *testing.T, caseNum int) bool {
|
||||||
if testJoinSplits == nil && txJoinSplits != nil {
|
if testJoinSplits == nil && txJoinSplits != nil {
|
||||||
t.Errorf("Test %d: non-zero joinSplits when expected empty vector", caseNum)
|
t.Errorf("Test %d: non-zero joinSplits when expected empty vector", caseNum)
|
||||||
|
|||||||
Reference in New Issue
Block a user