2024-02-13 07:04:56 +00:00
|
|
|
package crypto_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/crypto"
|
2024-10-12 18:55:17 +00:00
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
|
2024-02-13 07:04:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMasterProve(t *testing.T) {
|
|
|
|
l, _ := zap.NewProduction()
|
|
|
|
w := crypto.NewWesolowskiFrameProver(l)
|
|
|
|
m, err := w.CreateMasterGenesisFrame([]byte{
|
2024-10-12 18:55:17 +00:00
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
2024-02-13 07:04:56 +00:00
|
|
|
}, bytes.Repeat([]byte{0x00}, 516), 10000)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2024-10-12 18:55:17 +00:00
|
|
|
next, err := w.ProveMasterClockFrame(
|
|
|
|
m,
|
|
|
|
time.Now().UnixMilli(),
|
|
|
|
10000,
|
|
|
|
[]*protobufs.InclusionAggregateProof{},
|
|
|
|
)
|
2024-02-13 07:04:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = w.VerifyMasterClockFrame(next)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2024-05-25 05:22:50 +00:00
|
|
|
|
2024-10-12 18:55:17 +00:00
|
|
|
func TestCalculateChallengeProofDifficulty(t *testing.T) {
|
2024-05-25 05:22:50 +00:00
|
|
|
l, _ := zap.NewProduction()
|
|
|
|
w := crypto.NewWesolowskiFrameProver(l)
|
2024-10-12 18:55:17 +00:00
|
|
|
|
|
|
|
// At 0 increments, the difficulty should be 200,000
|
|
|
|
difficulty0 := w.CalculateChallengeProofDifficulty(0)
|
|
|
|
assert.Equal(t, 200000, difficulty0)
|
|
|
|
|
|
|
|
// At 100,000 increments, the difficulty should be 175,000
|
|
|
|
difficulty100k := w.CalculateChallengeProofDifficulty(100000)
|
|
|
|
assert.Equal(t, 175000, difficulty100k)
|
|
|
|
|
|
|
|
// At 700,000 increments, the difficulty should be 25,000
|
|
|
|
difficulty700k := w.CalculateChallengeProofDifficulty(700000)
|
|
|
|
assert.Equal(t, 25000, difficulty700k)
|
|
|
|
|
|
|
|
// At 800,000 increments, the difficulty should stay at 25,000
|
|
|
|
difficulty800k := w.CalculateChallengeProofDifficulty(800000)
|
|
|
|
assert.Equal(t, 25000, difficulty800k)
|
2024-05-25 05:22:50 +00:00
|
|
|
}
|