示例#1
0
// validateReplaceSeries validate the created series stored in the system
// corresponds to the series we replaced the original with.
func validateReplaceSeries(t *testing.T, pool *vp.Pool, testID int, replacedWith seriesRaw) {
	seriesID := replacedWith.id
	series := pool.Series(seriesID)
	if series == nil {
		t.Fatalf("Test #%d Series #%d: series not found", testID, seriesID)
	}

	pubKeys := series.TstGetRawPublicKeys()
	// Check that the public keys match what we expect.
	if !reflect.DeepEqual(replacedWith.pubKeys, pubKeys) {
		t.Errorf("Test #%d, series #%d: pubkeys mismatch. Got %v, want %v",
			testID, seriesID, pubKeys, replacedWith.pubKeys)
	}

	// Check number of required sigs.
	if replacedWith.reqSigs != series.TstGetReqSigs() {
		t.Errorf("Test #%d, series #%d: required signatures mismatch. Got %d, want %d",
			testID, seriesID, series.TstGetReqSigs(), replacedWith.reqSigs)
	}

	// Check that the series is not empowered.
	if series.IsEmpowered() {
		t.Errorf("Test #%d, series #%d: series is empowered but should not be",
			testID, seriesID)
	}
}
示例#2
0
func validateLoadAllSeries(t *testing.T, pool *vp.Pool, testID int, seriesData seriesRaw) {
	series := pool.Series(seriesData.id)

	// Check that the series exists.
	if series == nil {
		t.Errorf("Test #%d, series #%d: series not found", testID, seriesData.id)
	}

	// Check that reqSigs is what we inserted.
	if seriesData.reqSigs != series.TstGetReqSigs() {
		t.Errorf("Test #%d, series #%d: required sigs are different. Got %d, want %d",
			testID, seriesData.id, series.TstGetReqSigs(), seriesData.reqSigs)
	}

	// Check that pubkeys and privkeys have the same length.
	publicKeys := series.TstGetRawPublicKeys()
	privateKeys := series.TstGetRawPrivateKeys()
	if len(privateKeys) != len(publicKeys) {
		t.Errorf("Test #%d, series #%d: wrong number of private keys. Got %d, want %d",
			testID, seriesData.id, len(privateKeys), len(publicKeys))
	}

	sortedKeys := vp.CanonicalKeyOrder(seriesData.pubKeys)
	if !reflect.DeepEqual(publicKeys, sortedKeys) {
		t.Errorf("Test #%d, series #%d: public keys mismatch. Got %v, want %v",
			testID, seriesData.id, sortedKeys, publicKeys)
	}

	// Check that privkeys are what we inserted (length and content).
	foundPrivKeys := make([]string, 0, len(seriesData.pubKeys))
	for _, privateKey := range privateKeys {
		if privateKey != "" {
			foundPrivKeys = append(foundPrivKeys, privateKey)
		}
	}
	foundPrivKeys = vp.CanonicalKeyOrder(foundPrivKeys)
	privKeys := vp.CanonicalKeyOrder(seriesData.privKeys)
	if !reflect.DeepEqual(privKeys, foundPrivKeys) {
		t.Errorf("Test #%d, series #%d: private keys mismatch. Got %v, want %v",
			testID, seriesData.id, foundPrivKeys, privKeys)
	}
}