test: re-enable disabled tests
1. Rewrite VRF test to actually test win counts, and enable it. 2. Stop skipping some tests that now pass.
This commit is contained in:
parent
714635c75c
commit
8e52bf30c1
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -129,17 +128,25 @@ func BenchmarkWinCounts(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWinCounts(t *testing.T) {
|
func TestWinCounts(t *testing.T) {
|
||||||
t.SkipNow()
|
|
||||||
totalPower := NewInt(100)
|
totalPower := NewInt(100)
|
||||||
power := NewInt(30)
|
power := NewInt(20)
|
||||||
|
|
||||||
f, _ := os.Create("output.wins")
|
count := uint64(1000000)
|
||||||
fmt.Fprintf(f, "wins\n")
|
total := uint64(0)
|
||||||
ep := &ElectionProof{VRFProof: nil}
|
ep := &ElectionProof{VRFProof: make([]byte, 5)}
|
||||||
for i := uint64(0); i < 1000000; i++ {
|
for i := uint64(0); i < count; i++ {
|
||||||
i := i + 1000000
|
w := i + count
|
||||||
ep.VRFProof = []byte{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24), byte(i >> 32)}
|
ep.VRFProof[0] = byte(w)
|
||||||
j := ep.ComputeWinCount(power, totalPower)
|
ep.VRFProof[1] = byte(w >> 8)
|
||||||
fmt.Fprintf(f, "%d\n", j)
|
ep.VRFProof[2] = byte(w >> 16)
|
||||||
|
ep.VRFProof[3] = byte(w >> 24)
|
||||||
|
ep.VRFProof[4] = byte(w >> 32)
|
||||||
|
|
||||||
|
total += uint64(ep.ComputeWinCount(power, totalPower))
|
||||||
}
|
}
|
||||||
|
// We have 1/5 of the power, so we expect to win 1 block per epoch on average. Plus or minus
|
||||||
|
// 1%.
|
||||||
|
avgWins := float64(total) / float64(count)
|
||||||
|
assert.GreaterOrEqual(t, avgWins, 1.0-0.01)
|
||||||
|
assert.LessOrEqual(t, avgWins, 1.0+0.01)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ func LoadVector(t *testing.T, f string, out interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockHeaderVectors(t *testing.T) {
|
func TestBlockHeaderVectors(t *testing.T) {
|
||||||
t.Skip("we need to regenerate for beacon")
|
|
||||||
var headers []HeaderVector
|
var headers []HeaderVector
|
||||||
LoadVector(t, "block_headers.json", &headers)
|
LoadVector(t, "block_headers.json", &headers)
|
||||||
|
|
||||||
@ -65,8 +64,6 @@ func TestMessageSigningVectors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUnsignedMessageVectors(t *testing.T) {
|
func TestUnsignedMessageVectors(t *testing.T) {
|
||||||
t.Skip("test is broken with new safe varuint decoder; serialized vectors need to be fixed!")
|
|
||||||
|
|
||||||
var msvs []UnsignedMessageVector
|
var msvs []UnsignedMessageVector
|
||||||
LoadVector(t, "unsigned_messages.json", &msvs)
|
LoadVector(t, "unsigned_messages.json", &msvs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user