Exemplo n.º 1
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)
	}
}
Exemplo n.º 2
0
func TestPoolSeries(t *testing.T) {
	tearDown, _, pool := vp.TstCreatePool(t)
	defer tearDown()
	expectedPubKeys := vp.CanonicalKeyOrder(vp.TstPubKeys[0:3])
	if err := pool.CreateSeries(vp.CurrentVersion, 1, 2, expectedPubKeys); err != nil {
		t.Fatalf("Failed to create series: %v", err)
	}

	series := pool.Series(1)

	if series == nil {
		t.Fatal("Series() returned nil")
	}
	pubKeys := series.TstGetRawPublicKeys()
	if !reflect.DeepEqual(pubKeys, expectedPubKeys) {
		t.Errorf("Series pubKeys mismatch. Got %v, want %v", pubKeys, expectedPubKeys)
	}
}
Exemplo n.º 3
0
}

type replaceSeriesTestEntry struct {
	testID      int
	orig        seriesRaw
	replaceWith seriesRaw
}

var replaceSeriesTestData = []replaceSeriesTestEntry{
	{
		testID: 0,
		orig: seriesRaw{
			id:      1,
			version: 1,
			reqSigs: 2,
			pubKeys: vp.CanonicalKeyOrder([]string{vp.TstPubKeys[0], vp.TstPubKeys[1],
				vp.TstPubKeys[2], vp.TstPubKeys[4]}),
		},
		replaceWith: seriesRaw{
			id:      1,
			version: 1,
			reqSigs: 1,
			pubKeys: vp.CanonicalKeyOrder(vp.TstPubKeys[3:6]),
		},
	},
	{
		testID: 1,
		orig: seriesRaw{
			id:      2,
			version: 1,
			reqSigs: 2,
			pubKeys: vp.CanonicalKeyOrder(vp.TstPubKeys[0:3]),