pool/clmscript/script_test.go

38 lines
837 B
Go
Raw Normal View History

2020-08-14 09:32:45 +02:00
package clmscript
import (
"testing"
"github.com/btcsuite/btcd/btcec"
"github.com/stretchr/testify/require"
)
const (
numOperations = 1000
)
// TestIncrementDecrementKey makes sure that incrementing and decrementing an EC
// public key are inverse operations to each other.
func TestIncrementDecrementKey(t *testing.T) {
t.Parallel()
privKey, err := btcec.NewPrivateKey(btcec.S256())
require.NoError(t, err)
randomStartBatchKey := privKey.PubKey()
// Increment the key numOperations times.
currentKey := randomStartBatchKey
for i := 0; i < numOperations; i++ {
currentKey = IncrementKey(currentKey)
}
// Decrement the key again.
for i := 0; i < numOperations; i++ {
currentKey = DecrementKey(currentKey)
}
// We should arrive at the same start key again.
require.Equal(t, randomStartBatchKey, currentKey)
}