|
@ -28,7 +28,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
|
|
|
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
|
|
|
vals = keys.ToValidators(20, 10) |
|
|
vals = keys.ToValidators(20, 10) |
|
|
bTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") |
|
|
bTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") |
|
|
header = keys.GenSignedHeader(chainID, lastHeight, bTime, nil, vals, vals, |
|
|
|
|
|
|
|
|
header = keys.GenSignedHeader(t, chainID, lastHeight, bTime, nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -51,7 +51,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// different chainID -> error
|
|
|
// different chainID -> error
|
|
|
1: { |
|
|
1: { |
|
|
keys.GenSignedHeader("different-chainID", nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, "different-chainID", nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -61,7 +61,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// new header's time is before old header's time -> error
|
|
|
// new header's time is before old header's time -> error
|
|
|
2: { |
|
|
2: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(-1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(-1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
4 * time.Hour, |
|
|
4 * time.Hour, |
|
@ -71,7 +71,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// new header's time is from the future -> error
|
|
|
// new header's time is from the future -> error
|
|
|
3: { |
|
|
3: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(3*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(3*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -81,7 +81,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// new header's time is from the future, but it's acceptable (< maxClockDrift) -> no error
|
|
|
// new header's time is from the future, but it's acceptable (< maxClockDrift) -> no error
|
|
|
4: { |
|
|
4: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, |
|
|
bTime.Add(2*time.Hour).Add(maxClockDrift).Add(-1*time.Millisecond), nil, vals, vals, |
|
|
bTime.Add(2*time.Hour).Add(maxClockDrift).Add(-1*time.Millisecond), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
vals, |
|
|
vals, |
|
@ -92,7 +92,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 3/3 signed -> no error
|
|
|
// 3/3 signed -> no error
|
|
|
5: { |
|
|
5: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -102,7 +102,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 2/3 signed -> no error
|
|
|
// 2/3 signed -> no error
|
|
|
6: { |
|
|
6: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 1, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 1, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -112,7 +112,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 1/3 signed -> error
|
|
|
// 1/3 signed -> error
|
|
|
7: { |
|
|
7: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), len(keys)-1, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), len(keys)-1, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -122,7 +122,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// vals does not match with what we have -> error
|
|
|
// vals does not match with what we have -> error
|
|
|
8: { |
|
|
8: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(1*time.Hour), nil, keys.ToValidators(10, 1), vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(1*time.Hour), nil, keys.ToValidators(10, 1), vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
keys.ToValidators(10, 1), |
|
|
keys.ToValidators(10, 1), |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -132,7 +132,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// vals are inconsistent with newHeader -> error
|
|
|
// vals are inconsistent with newHeader -> error
|
|
|
9: { |
|
|
9: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
keys.ToValidators(10, 1), |
|
|
keys.ToValidators(10, 1), |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -142,7 +142,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// old header has expired -> error
|
|
|
// old header has expired -> error
|
|
|
10: { |
|
|
10: { |
|
|
keys.GenSignedHeader(chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, nextHeight, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
keys.ToValidators(10, 1), |
|
|
keys.ToValidators(10, 1), |
|
|
1 * time.Hour, |
|
|
1 * time.Hour, |
|
@ -180,7 +180,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) { |
|
|
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
|
|
|
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
|
|
|
vals = keys.ToValidators(20, 10) |
|
|
vals = keys.ToValidators(20, 10) |
|
|
bTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") |
|
|
bTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") |
|
|
header = keys.GenSignedHeader(chainID, lastHeight, bTime, nil, vals, vals, |
|
|
|
|
|
|
|
|
header = keys.GenSignedHeader(t, chainID, lastHeight, bTime, nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) |
|
|
|
|
|
|
|
|
// 30, 40, 50
|
|
|
// 30, 40, 50
|
|
@ -206,7 +206,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) { |
|
|
}{ |
|
|
}{ |
|
|
// 3/3 new vals signed, 3/3 old vals present -> no error
|
|
|
// 3/3 new vals signed, 3/3 old vals present -> no error
|
|
|
0: { |
|
|
0: { |
|
|
keys.GenSignedHeader(chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -216,7 +216,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 2/3 new vals signed, 3/3 old vals present -> no error
|
|
|
// 2/3 new vals signed, 3/3 old vals present -> no error
|
|
|
1: { |
|
|
1: { |
|
|
keys.GenSignedHeader(chainID, 4, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, 4, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 1, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 1, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -226,7 +226,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 1/3 new vals signed, 3/3 old vals present -> error
|
|
|
// 1/3 new vals signed, 3/3 old vals present -> error
|
|
|
2: { |
|
|
2: { |
|
|
keys.GenSignedHeader(chainID, 5, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
|
|
|
|
|
keys.GenSignedHeader(t, chainID, 5, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), len(keys)-1, len(keys)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), len(keys)-1, len(keys)), |
|
|
vals, |
|
|
vals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -236,7 +236,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 3/3 new vals signed, 2/3 old vals present -> no error
|
|
|
// 3/3 new vals signed, 2/3 old vals present -> no error
|
|
|
3: { |
|
|
3: { |
|
|
twoThirds.GenSignedHeader(chainID, 5, bTime.Add(1*time.Hour), nil, twoThirdsVals, twoThirdsVals, |
|
|
|
|
|
|
|
|
twoThirds.GenSignedHeader(t, chainID, 5, bTime.Add(1*time.Hour), nil, twoThirdsVals, twoThirdsVals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(twoThirds)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(twoThirds)), |
|
|
twoThirdsVals, |
|
|
twoThirdsVals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -246,7 +246,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 3/3 new vals signed, 1/3 old vals present -> no error
|
|
|
// 3/3 new vals signed, 1/3 old vals present -> no error
|
|
|
4: { |
|
|
4: { |
|
|
oneThird.GenSignedHeader(chainID, 5, bTime.Add(1*time.Hour), nil, oneThirdVals, oneThirdVals, |
|
|
|
|
|
|
|
|
oneThird.GenSignedHeader(t, chainID, 5, bTime.Add(1*time.Hour), nil, oneThirdVals, oneThirdVals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(oneThird)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(oneThird)), |
|
|
oneThirdVals, |
|
|
oneThirdVals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -256,7 +256,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) { |
|
|
}, |
|
|
}, |
|
|
// 3/3 new vals signed, less than 1/3 old vals present -> error
|
|
|
// 3/3 new vals signed, less than 1/3 old vals present -> error
|
|
|
5: { |
|
|
5: { |
|
|
lessThanOneThird.GenSignedHeader(chainID, 5, bTime.Add(1*time.Hour), nil, lessThanOneThirdVals, lessThanOneThirdVals, |
|
|
|
|
|
|
|
|
lessThanOneThird.GenSignedHeader(t, chainID, 5, bTime.Add(1*time.Hour), nil, lessThanOneThirdVals, lessThanOneThirdVals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(lessThanOneThird)), |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(lessThanOneThird)), |
|
|
lessThanOneThirdVals, |
|
|
lessThanOneThirdVals, |
|
|
3 * time.Hour, |
|
|
3 * time.Hour, |
|
@ -296,7 +296,7 @@ func TestVerifyReturnsErrorIfTrustLevelIsInvalid(t *testing.T) { |
|
|
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
|
|
|
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
|
|
|
vals = keys.ToValidators(20, 10) |
|
|
vals = keys.ToValidators(20, 10) |
|
|
bTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") |
|
|
bTime, _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z") |
|
|
header = keys.GenSignedHeader(chainID, lastHeight, bTime, nil, vals, vals, |
|
|
|
|
|
|
|
|
header = keys.GenSignedHeader(t, chainID, lastHeight, bTime, nil, vals, vals, |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) |
|
|
hash("app_hash"), hash("cons_hash"), hash("results_hash"), 0, len(keys)) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|